<?php 
      
      use Facebook\FacebookSession;
use Facebook\FacebookRedirectLoginHelper;
use Facebook\FacebookRequest;
use Facebook\FacebookResponse;
use Facebook\FacebookSDKException;
use Facebook\FacebookRequestException;
use Facebook\FacebookAuthorizationException;
use Facebook\GraphObject;
use Facebook\Entities\AccessToken;
use Facebook\HttpClients\FacebookCurlHttpClient;
use Facebook\HttpClients\FacebookHttpable; 
       
      class ajax extends model  { 

         private $arraydata=array();
      
           function __construct()
           { 
            
             global $db_exec,$info,$memcache;
             $this->db=$db_exec;   
             $this->db->get_connect();
             $this->info=$info; 
             $this->memcache=$memcache;
             //echo "ddd";
            
             if($_POST)
             {
             $this->post=$_POST;
             }
             if($_GET)
             {
             $this->get=$_GET;
             }
             
             

             if($this->info['parameter'][1]=='nojson')
             {
             
             }else
             {
             if($this->get['nojson']!=1)
             {
             ob_start();
             ob_start('ob_gzhandler');
           
             }
             }
             
             
             if($_COOKIE['oauth'])
             {
             $this->userdata=$_COOKIE;
             } 
             
             
             
             if($_GET['oauth'])
             {
             
             $this->userdata=$this->getuserbyoauth($_GET['oauth']);

             
             }
             
             
             if($_POST['oauth'])
             {
             $this->userdata=$this->getuserbyoauth($_POST['oauth']);
             
             
             } 
             

             
             if(method_exists($this,$this->info['parameter'][0]))
             {
              eval("\$this->".$this->info['parameter'][0]."();");     
                 
             }else
             {
                $this->arraydata['error'][]=2;
                
             }
                 
                                    
           
           }
           
           function test()
           {
          $this->arraydata['data']= $this->configdataset();
           
           }
           
           
           
           function testdatapassword()
           {
           
           $data=htmlspecialchars(trim($input), ENT_QUOTES);
           $data=mysql_real_escape_string($data);
    
    $input="admin2011";
           
           
            echo  md5($input);
           }
           
           
           function getcarthistory()
           {
            $userdata=$this->getuserbyoauth($this->userdata['oauth']);
           if($userdata['userid'])
           {
       
           
           $this->arraydata['data']=parent::getcarthistory($userdata['userid']);
           
           }
           
           }
           
           function getbannercellbyfid()
           {
           if($this->get['fid'])
           {
           $fid=$this->get['fid'];
           }else
           {
           $fid=0;
           }

            $arraydata=$this->memcache->get($fid.'getbannercellbyfid') ;
            
           if(count($arraydata))
           {

           
           $this->arraydata['data']=$arraydata;
           
           }
            else
            {
           
           
           if($this->get['fid'])
           {
            $featureall=$this->getfeaturebyfid($this->get['fid'],0);
            
            if(count($featureall['bannercell']['web']))
            {
            $k=0;
            foreach($featureall['bannercell']['web'] as $valuewebbanner)
            {
            
            $featureall['bannercell']['web'][$k]['img']=bannerinfo.'/'.$valuewebbanner['img'];
            $k++;
            
            }
            }
            else
            {
            $featureall['bannercell']['web']=array();
            }
            
            $this->arraydata['data']=$featureall['bannercell']['web'];
            
            
            $this->memcache->set($fid.'getbannercellbyfid',$this->arraydata['data']) ; 
           
           }else
           {
           
           if(count($this->info['configall']['bannercell']['web']))
            {
            $k=0;
            foreach($this->info['configall']['bannercell']['web'] as $valuewebbanner)
            {
            
            $this->info['configall']['bannercell']['web'][$k]['img']=bannerinfo.'/'.$valuewebbanner['img'];
            $k++;
            
            }
            }
            else
            {
            $this->info['configall']['bannercell']['web']=array();
            }
            
             
            
            
           
          $this->arraydata['data']= $this->info['configall']['bannercell']['web'];
           
           
           $this->memcache->set($fid.'getbannercellbyfid',$this->arraydata['data']) ; 
           }
           
           
           
           
           
           
            }
           
           }
           
           function getallbannercell()
           {
           $arraynewdata=array();
           $arraydata=array();
           $k=0;
           $x=0;
           if(count($this->info['configall']['bannercell']['web']))
           {

           foreach($this->info['configall']['bannercell']['web'] as $valuebannercell)
           {
           $arraydata[$k]['fid']=0;
           $arraydata[$k]['img']=bannerinfo.'/'.$valuebannercell['img'];
           $arraydata[$k]['link']=$valuebannercell['link'];
           $arraydata[$k]['position']=$valuebannercell['position'];
           $arraydata[$k]['productid']=$valuebannercell['productid'];
           $k++;
           
           }
           $arraynewdata["0"]=$arraydata;
           
           
           }
           
           if(count($this->info['configall']['feature']))
           {
           foreach($this->info['configall']['feature'] as $valuefeature)
           {
            if($valuefeature['bannercell'])
            {
            //$arraynewdata[$x]['fid']=;
            $k=0;
            foreach($valuefeature['bannercell']['web'] as $valuebannercell)
           {
           $arraydata[$k]['fid']=$valuefeature['fid'];
           $arraydata[$k]['img']=bannerinfo.'/'.$valuebannercell['img'];
           $arraydata[$k]['link']=$valuebannercell['link'];
           $arraydata[$k]['position']=$valuebannercell['position'];
           $arraydata[$k]['productid']=$valuebannercell['productid'];
           $k++;
           
           }
           $arraynewdata[$valuefeature['fid'].'']=$arraydata;
           $x++;
            
            }
            }
           
           
           }
           
           $this->arraydata['data']=$arraynewdata;
           
           
           }
           
           function getallbannerlanding2()
           {
           
           
           $arraydata=array();
           $k=0;

           
           if(count($this->info['configall']['feature']))
           {
           foreach($this->info['configall']['feature'] as $valuefeature)
           {
            if($valuefeature['bannerlanding'])
            {
            $k=0;
            foreach($valuefeature['bannerlanding']['web'] as $valuebannercell)
           {
           $arraydata[$valuefeature['fid']][$k]['fid']=$valuefeature['fid'];
           $arraydata[$valuefeature['fid']][$k]['img']=bannerinfo.'/'.$valuebannercell['img'];
           $arraydata[$valuefeature['fid']][$k]['link']=$valuebannercell['link'];
           if($valuebannercell['productid'])
           {
           $arraydata[$valuefeature['fid']][$k]['productid']=$valuebannercell['productid'];
           }else
           {
           $arraydata[$valuefeature['fid']][$k]['productid']=0;
           
           }
           
           
           $k++;
           
           }
            }
            }
           
           
           }
           
           
           
           
           $this->arraydata['data']=$arraydata;
           
           
           }
           function removeitemproduct()
           {
           if($this->post['productid']&&$this->post['userid'])
           {
           $userdata=$this->getuserbyoauth($this->userdata['oauth']);
           $arraydata['delete']=1;
           $this->db->db_set($arraydata,'tb_product_shop_history',' userid='.$this->post['userid'].' and createby='.$userdata['userid'].' and productid='.$this->post['productid'].' and  tb_product_shop_history.delete=0 and paypoint=0');
           
           
           
           }
           
           
           
           }
           function emptycartproduct()
           {
            if($this->post['userid'])
           {
           $userdata=$this->getuserbyoauth($this->userdata['oauth']);
           $arraydata['delete']=1;
           $this->db->db_set($arraydata,'tb_product_shop_history',' userid='.$this->post['userid'].' and createby='.$userdata['userid'].'  and  tb_product_shop_history.delete=0');
           
           
           
           }
           
           
           }
           
           function getallbannerlanding()
           {
           
           
           $arraydata=array();
           $k=0;

           
           if(count($this->info['configall']['feature']))
           {
           foreach($this->info['configall']['feature'] as $valuefeature)
           {
            if($valuefeature['bannerlanding'])
            {
            $k=$valuefeature['fid'].'';
            foreach($valuefeature['bannerlanding']['web'] as $valuebannercell)
           {
           $arraydata[$k]['fid']=$valuefeature['fid'];
           $arraydata[$k]['img']=bannerinfo.'/'.$valuebannercell['img'];
           $arraydata[$k]['link']=$valuebannercell['link'];
           if($valuebannercell['productid'])
           {
           $arraydata[$k]['productid']=$valuebannercell['productid'];
           }else
           {
           $arraydata[$k]['productid']=0;
           
           }
           
           
           $k++;
           
           }
            }
            }
           
           
           }
           
           
           
           
           $this->arraydata['data']=$arraydata;
           
           
           }
           
           function getbannerlandingbyfid()
           {
           if($this->get['fid'])
           {
           $this->arraydata['data']=parent::getbannerlandingbyfid($this->get['fid']);
           
           }
           
           }
           
           
           function testdatapost()
           {
           
           echo "<pre>";
           print_r($_POST);
           echo "</pre>;";
           }
           
           
           function exportuserall()
           {
           
           $arrayuser=$this->getuserbyoauth($this->userdata['oauth']);
      if($arrayuser['userid']&&($arrayuser['roleid']=='3'||$arrayuser['roleid']=='4'))
            {      
           header("Content-Type: application/vnd.ms-excel");
          header('Content-Disposition: attachment; filename="tb_data_'.time().'.xls"');
           
           $where='';
           if($this->get['datedatafrom']&&$this->get['datedatato'])
           {
           list($day,$month,$year)=explode("/",$this->get['datedatafrom']);
           list($day2,$month2,$year2)=explode("/",$this->get['datedatato']);
           $from=$year.'-'.$month.'-'.$day.' 00:00:00';
           $to=$year2.'-'.$month2.'-'.$day2.' 23:59:59';
           $where=' where tb_user.createdate between "'.$from.'" AND "'.$to.'" ';
           
           
           }
           
           
           $sql='select IF (
    tb_user.email = \'\',
    tb_user.emailfacebook,
    tb_user.email
) AS email,status,IF (tb_user.displayname = \'\', tb_user.username,tb_user.displayname) as displayname,
tb_user.phone,
tb_user.username,
tb_user.firstname,
tb_user.lastname,
tb_user.userid,
tb_user.roleid,
tb_user.createdate 
from tb_user '.$where.'  order by tb_user.createdate desc ';
           
           $arrayuser=$this->db->db_set_recordset($sql);
           ?>
           
   <html xmlns:o="urn:schemas-microsoft-com:office:office"

xmlns:x="urn:schemas-microsoft-com:office:excel"

xmlns="http://www.w3.org/TR/REC-html40">


<HTML>

<HEAD>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

</HEAD><BODY>

<TABLE  x:str BORDER="1">



<tr align="center">
    <td>No</td>
    <td>Userid</td>
    <td>Firstname</td>
    <td>Lastname</td>
    <td>Displayname</td>
    <td>Username</td>
    <td>Email</td>
    <td>Tel</td> 
    <td>Active</td> 
    <td>Role</td> 
    <td>Serial</td> 
    <td>Createdate</td> 
  </tr>
    
  
 <?
 if(count($arrayuser))
{
$k=1;
foreach($arrayuser as $valueuser)
{

?>
<tr align="center">
    <td><?=$k?></td>
    <td><?=$valueuser['userid']?></td>
    <td><?=$valueuser['firstname']?></td>
    <td><?=$valueuser['lastname']?></td>
    <td><?=$valueuser['displayname']?></td>
    <td><?=$valueuser['username']?></td>
    <td><?=$valueuser['email']?></td> 
    <td><?=$valueuser['phone']?></td> 
    <td><?=$valueuser['status']?></td> 
    <td><?=$valueuser['roleid']?></td>
    
    <?
    $sql='select serial from tb_serial where createby='.$valueuser['userid'];
    $arrayserial=$this->db->db_set_recordset($sql);
    $serial=array();
    $strserial='';
    if(count($arrayserial))
    {
    foreach($arrayserial as $valueserial)
    {
    
    $serial[]=$valueserial['serial'];
    
    }
    
    $strserial=join(',',$serial);
    }
    
    
    
    ?>
    <td><?=$strserial?></td>
    
    
    <td><?=$valueuser['createdate']?></td> 
  </tr>


<?

$k++;
}


} 
 
 ?>
 
 
    
  
  </TABLE>
  
  </BODY>

  </HTML>
  
  <?
           
           
            }  
           
           }
           
             function addpaycredit()
           {
           $arrayuser=$this->getuserbyoauth($this->userdata['oauth']);
           

                       if($arrayuser['userid']&&$this->post['coin']&&$this->post['userid']&&($arrayuser['roleid']=='3'||$arrayuser['roleid']=='4'))
            {
            
            $sql='select credit,creditid from tb_pay_credit where userid='.$this->post['userid'];
            $paycredit=$this->db->db_set_1recordrow($sql);
            $arraydata=array();
            $arraydata['updatedate']=date("Y-m-d H:i:s");
            
            if($paycredit['creditid'])
            {
            
            $total=intval($paycredit['credit'])+intval($this->post['coin']);
            $arraydata['credit']=$total;
            $this->db->db_set($arraydata,'tb_pay_credit',' creditid='.$paycredit['creditid']);
            
            
            }else
            {
            
            $arraydata['credit']=$this->post['coin'];
            $arraydata['userid']=$this->post['userid'];
            $arraydata['createdate']=date("Y-m-d H:i:s");
            $this->db->db_set($arraydata,'tb_pay_credit');
            
            
            }
            
            
            $arraydata['credit']=$this->post['coin'];
            $arraydata['userid']=$this->post['userid'];
            $arraydata['status']=1;
            $arraydata['createby']=$arrayuser['userid'];
            $arraydata['createdate']=date("Y-m-d H:i:s");
            $this->db->db_set($arraydata,'tb_pay_credit_history');
            
            }
            
            
           }
           
           function getuseralldata2()
           {
           $arrayuser=$this->getuserbyoauth($this->userdata['oauth']);
           

                       if($arrayuser['userid']&&$this->get['page']&&($arrayuser['roleid']=='3'||$arrayuser['roleid']=='4'))
            {
            

            $page=$this->get['page'];
            $page=(($page - 1) * 20);
            $limit="limit  $page,".'20';
           
           $where='';
           if($this->get['search'])
           {
           
           $where='where tb_user.username like "%'.$this->get['search'].'%" or tb_user.email like "%'.$this->get['search'].'%"';
           
           
           }
           
           $sql='select tb_user.userid,username,IF (
    tb_user.email = \'\',
    tb_user.emailfacebook,
    tb_user.email
) AS email,roleid,status,DATE_FORMAT(tb_user.createdate,\'%d/%m/%Y\') as newdate,IF(tb_pay_credit.credit is NULL,0,tb_pay_credit.credit) as credit from tb_user LEFT JOIN tb_pay_credit ON tb_pay_credit.userid = tb_user.userid '.$where.' order by tb_user.createdate desc '.$limit;
           
           $this->arraydata['data']=$this->db->db_set_recordset($sql);
           
           $this->getcreditdata();

           
           $sql='select count(userid) as countdata from tb_user '.$where;
           $arraydata=$this->db->db_set_1recordrow($sql);
           $this->arraydata['count']=intval($arraydata['countdata']);
           $this->arraydata['count']=ceil($this->arraydata['count']/countpage);
           
           
           
           
            }
           
           }
           
           function uploaddata()
           {
           

           

             

               $arrayuser=$this->getuserbyoauth($this->userdata['oauth']);
           

                     if($arrayuser['userid']&&$this->post['fileid']&&($arrayuser['roleid']=='3'||$arrayuser['roleid']=='4'))
            {
              
              $sql='select path from tb_file where fileid='.$this->post['fileid'].' and path like "%.csv%"';
              $data2=$this->db->db_set_1recordrow($sql);
              
                

              if ($data2['path']) 
              {
              


            //  require_once(pluginpath.'/parsecsv/parsecsv.lib.php');
              require_once(pluginpath.'/parsecsv/DataSource.php');
              require_once(pluginpath.'/phpmailer/class.config.php'); // uri
            //  $csv = new parseCSV();
             // echo $newname;
             // $csv->auto($newname);
              
              $csv = new File_CSV_DataSource;
            //  $newname='/var/www/ibestdiscount/quiz/library/plugin/parsecsv/examples/_books.csv';
              $data=$csv->load($data2['path']); // boolean
              
          //   $arraydata= $csv->getColumn('Initial');

            $arraydata=$csv->connect();

              
//              $row = 1;
//if (($handle = fopen($newname, "r")) !== FALSE) {
//    while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
//        $num = count($data);
       // echo "<p> $num fields in line $row: <br /></p>\n";
//        $row++;
//        for ($c=0; $c < $num; $c++) {
//            $rownow=$data[$c];
//        }
//    }
//    fclose($handle);
//}
                $mail = new ConfigMail();
                 

              
              if(count($arraydata))
              {
              foreach($arraydata as $valuedata)
              {
              
                

                if($valuedata['email']&&$valuedata['username']&&$valuedata['password'])
                {
                $arraynewdata=array();
                
                
                $newpass=$valuedata['password'];
                
                $newpass=md5($newpass.'-123456');
                
                
              
                
                
                
                
                $sql='select userid from tb_user where email="'.trim($valuedata['email']).'" or  username="'.trim($valuedata['username']).'" ';
                $arrayuser=$this->db->db_set_1recordrow($sql);
                if(!$arrayuser['userid'])
                {
                $arraynewdata['username']=trim($valuedata['username']);
                $arraynewdata['password']=$newpass;
                $arraynewdata['displayname']=trim($valuedata['username']);
                $arraynewdata['email']=trim($valuedata['email']);
                $arraynewdata['status']=1;
                $arraynewdata['createdate']=date("Y-m-d H:i:s");
                $this->db->db_set($arraynewdata,'tb_user');
                }
           
                
                
                
                
                
                
                
                
                
                
                }
                else if($valuedata['Userid'])
                {
                
                
                $sql='select roleid from tb_user where userid='.$valuedata['Userid'];
                $datarow=$this->db->db_set_1recordrow($sql);
                
                $check=false;
                if(intval($datarow['roleid'])!=intval($valuedata['Role']))
                {
                $check=true;
                
                }
                
                $userid=trim($valuedata['Userid']);
                $arraynewdata=array();
                $arraynewdata['firstname']=trim($valuedata['Firstname']);
                $arraynewdata['lastname']=trim($valuedata['Lastname']);
                $arraynewdata['displayname']=trim($valuedata['Displayname']);

                $arraynewdata['status']=trim($valuedata['Active']);
                $arraynewdata['roleid']=trim($valuedata['Role']);
                $arraynewdata['phone']=trim($valuedata['Tel']);

                $this->db->db_set($arraynewdata,'tb_user',' userid='.$userid);
                
                
                
           
           
                        
           //$mail->setFrom("s_chanyut@hotmail.com","Bird Kung");
                       if($check)
                       {
                       $mail->setTo($valuedata['Email'],$valuedata['Username']);
                       $mail->setContent('คุณได้ลงทะเบียนเข้าร่วมกิจกรรม Canon Professional เรียบร้อยแล้ว สถานะของคุณคือ Member Plus โดยสมาชิกสามารถ Login อีกครั้งเพื่อส่งรูปเข้าประกวดได้เลยค่ะ');
                       $mail->setSubject("ลงทะเบียนเข้าร่วม Canon Professional กับ ".NameDmconnex." เรียบร้อย");
                       
                       $mail->sendTo();
                       
                       
                       $mail->setClearAddress();
                       }
                
                
                
                }
              
              }
              
              }
              
              
               
              }
             
             }
            
             
           }
           
           
           function activeuserdata()
           {
           $arrayuser=$this->getuserbyoauth($this->userdata['oauth']);
            
            if($arrayuser['userid']&&isset($this->post['status'])&&$this->post['userid']&&($arrayuser['roleid']=='3'||$arrayuser['roleid']=='4'))
            {
            $arraydata['status']=$this->post['status'];
            $this->db->db_set($arraydata,'tb_user',' userid='.$this->post['userid']);
            
            
            
            }
           
           
           }
           
           function changeroledata()
           {
           
           $arrayuser=$this->getuserbyoauth($this->userdata['oauth']);
            
            if($arrayuser['userid']&&isset($this->post['roleid'])&&$this->post['userid']&&($arrayuser['roleid']=='3'||$arrayuser['roleid']=='4'))
            {
            $arraydata['roleid']=$this->post['roleid'];
            $this->db->db_set($arraydata,'tb_user',' userid='.$this->post['userid']);
            
            
            
            }
           
           
           }
           
           
           
           function forgetpassworddata()
           {
           $arrayuser=$this->getuserbyoauth($this->userdata['oauth']);
           if($arrayuser['userid']&&$this->post['userid']&&($arrayuser['roleid']=='3'||$arrayuser['roleid']=='4'))
           {
           
           $sql=" select IF (
    tb_user.email = \'\',
    tb_user.emailfacebook,
    tb_user.email
) AS email,username from tb_user where userid='".$this->post['userid']."'";
           $arrayuser=$this->db->db_set_recordset($sql);
           if($arrayuser[0]['userid'])
           {
           $newpassword=substr(md5(mktime().$arrayuser[0]['username'].$arrayuser[0]['email']),0,10);
         //  echo $newpassword;
           $arraydata['password']=md5($newpassword.'-123456');
           
           $this->db->db_set($arraydata,"tb_user"," userid=".$arrayuser[0]['userid']);
           
           
           require_once(pluginpath.'/phpmailer/class.config.php'); // uri
           
           $mail = new ConfigMail();
           //$mail->setFrom("s_chanyut@hotmail.com","Bird Kung");
           $mail->setTo($arrayuser[0]['email'],$arrayuser[0]['username']);
           $mail->setContent('We send new password to your email already ,Username is '.$arrayuser[0]['username'].', Password is '.trim($newpassword).'<br><a href="'.baseinfo.'" target="_blank">'.baseinfo.'</a>');
           $mail->setSubject("Send New Password From ".NameDmconnex);
           $mail->sendTo();
         //  $this->arraydata['password']=$newpassword;
           
           }else
           {
           $this->arraydata['error'][]=5;
           
           }
           }else
           {
           
           $this->arraydata['error'][]=4;
           
           }
           
           }
           
           function deleteuserdata()
           {
           
           $arrayuser=$this->getuserbyoauth($this->userdata['oauth']);
            
            if($arrayuser['userid']&&$this->post['userid']&&($arrayuser['roleid']=='3'||$arrayuser['roleid']=='4'))
            {
            
            $sql='delete from tb_user where userid='.$this->post['userid'];
            $this->db->db_delete($sql);
            
            
            
            }
           
           
           }
           
           
           
           function favproduct()
            {
//$sql='select * from tb-s';
//            $this->db->db_set_1recordrow($sql);
            if($this->post['productid']&&$this->userdata['oauth'])
            {
                
              $boolean=$this->favfunction($this->post['productid'],$this->userdata['oauth']);
              if($boolean)
              {
               $this->arraydata['data']['countlike']=$this->countfav($this->post['productid']);
               $this->arraydata['data']['checklike']=$this->checkuserfav($this->post['productid'],$this->userdata['oauth']);
               
              
              }else
              {
              $this->arraydata['error'][]=24;   
              
              }
             
            
            }else
            {
            $this->arraydata['error'][]=5;
            
            }
            
            
            
            }
           function paywithpoint()
           {
           
           if($this->userdata['oauth']&&$this->post['userid']&&$this->post['productid']&&$this->post['qty'])
           {
           $userdata=$this->getuserbyoauth($this->userdata['oauth']);
           
           $sql='select  psetid,paypoint,point from tb_product_setting where createby='.$this->post['userid'];
           $arraysetting=$this->db->db_set_1recordrow($sql);
           $changepoint=0;
           if($arraysetting['psetid']&&$arraysetting['paypoint']=='1'&&$arraysetting['point']!='0')
           {
           $changepoint=1;
           
           
           }
           
           
           $sql='select tb_plugins_pricefull.point,tb_plugins_pricefull.realprice,userpoint,priceid,unlimit,amount from tb_plugins_pricefull where tb_plugins_pricefull.productid='.$this->post['productid'].' and userpoint=1';
           $arraypoint=$this->db->db_set_1recordrow($sql);
           
           if($arraypoint['priceid'])
           {
           
           if($arraypoint['unlimit']=='0')
           {
           $amount=intval($arraypoint['amount']);
           if($amount<intval($this->post['qty']))
           {
           $this->arraydata['error'][]=44;
           exit;
           }
           
           
           }
           
           $point=intval($arraypoint['point'])*intval($this->post['qty']);
           $mypoint=$this->getpoint($userdata['userid']);
           
            if($changepoint&&($mypoint<$point))
           {
           $point=intval($arraypoint['realprice'])*intval($arraysetting['point'])*intval($this->post['qty']);
           
           }
           
           if($point)
           {
           
          
           
           if($mypoint>=$point)
           {
           $arraysuborder=array();
           $arraysuborder[0]['productid']=$this->post['productid'];
           $arraysuborder[0]['credit']=0;
           $arraysuborder[0]['count']=$this->post['qty'];
           $arraysuborder[0]['point']=$point;
           $arraysuborder[0]['discount']=0;
           $arraysuborder[0]['price']=$arraypoint['realprice'];
           $arraysuborder[0]['note']='';
           $arraysuborder[0]['suborderid']=$this->post['suborderid'];
           
           
           $orderid=$this->post['orderid'];
           if($orderid)
           {
           $sql='select point,sumall from tb_product_order where orderid='.$orderid;
           $arraydataorder=$this->db->db_set_1recordrow($sql);
           
           $newpoint=intval($arraydataorder['point'])+$point;
           $newsumall=intval($arraydataorder['sumall'])+(intval($arraypoint['realprice'])*intval($this->post['qty']));
           $this->arraydata['data']=$this->saveorderdata($arraysuborder,1,$newsumall,0,0,$newpoint,$userdata['userid'],$this->post['userid'],$orderid);
           }else
           {
           $realprice=intval($arraypoint['realprice'])*intval($this->post['qty']);
           
           $this->arraydata['data']=$this->saveorderdata($arraysuborder,1,$realprice,0,0,$point,$userdata['userid'],$this->post['userid'],0);
           
           }
           
           $sql='select shisid from tb_product_shop_history where tb_product_shop_history.productid='.$this->post['productid'].' and tb_product_shop_history.status=0 and tb_product_shop_history.delete=0 and tb_product_shop_history.createby='.$userdata['userid'];
           $productshop=$this->db->db_set_1recordrow($sql);
           $arrayset=array();
           
           $arrayset['paypoint']=1;
           $arrayset['orderid']=$this->arraydata['data']['orderid'];
           $arrayset['suborderid']=$this->arraydata['data']['suborderids'][0];
           $arrayset['quantity']=$this->post['qty'];
           $arrayset['updatedate']=date('Y-m-d H:i:s');
           $this->db->db_set($arrayset,'tb_product_shop_history',' shisid='.$productshop['shisid']);

           $arrayset=array();
           $arrayset['updatedate']=date('Y-m-d H:i:s');
           $arrayset['orderid']=$this->arraydata['data']['orderid'];
           $this->db->db_set($arrayset,'tb_product_shop_history',' tb_product_shop_history.status=0 and tb_product_shop_history.delete=0 and tb_product_shop_history.createby='.$userdata['userid'].' and tb_product_shop_history.userid='.$this->post['userid']);
           
           
           $arrayset=array();
           $arrayset['point']=$point;
           $arrayset['pointall']=$mypoint-$point;
           $arrayset['productid']=$this->post['productid'];
           $arrayset['orderid']=$this->arraydata['data']['orderid'];
           $arrayset['createby']=$userdata['userid'];
           $arrayset['createdate']=date('Y-m-d H:i:s');
           $this->db->db_set($arrayset,'tb_product_point_history');
           
           
           $this->saveproducttranfer($this->post['qty'],1,$this->post['userid'],$this->post['productid'],$this->arraydata['data']['orderid'],$this->arraydata['data']['suborderids'][0]);
           
           $this->changeproductstock($this->post['qty'],$this->post['productid']);
           
           $this->changepointstock($point,$userdata['userid']);
           
           
           
           }else
           {
           
           $this->arraydata['error'][]=43;
           
           }
           
           }else
           {
           $this->arraydata['error'][]=42;
           
           }
           
           }else
           {
           $this->arraydata['error'][]=42;
           
           }
           
           
           
           }
           
           
           }
           function savehistorypayment()
           {
            if($this->userdata['oauth'])
           {
           $userdata=$this->getuserbyoauth($this->userdata['oauth']);
           if($userdata['userid']&&$this->post['orderid']&&$this->post['shopid'])
           {
           $arraydata['tfid']=$this->post['tfid'];
           list($d,$m,$y)=explode("/",$this->post['datepay']);
           $arraydata['datepay']=$y.'-'.$m.'-'.$d.' '.$this->post['timepay'].':'.$this->post['minpay'].':00';
           $arraydata['amount']=$this->post['amount'];
           $arraydata['detail']=$this->post['detail'];
           $arraydata['imgmid']=$this->post['imgmid'];
           $arraydata['simgmid']=$this->post['simgmid'];
           $arraydata['orderid']=$this->post['orderid'];
           $arraydata['shopid']=$this->post['shopid'];
           $arraydata['createby']=$userdata['userid'];
           $arraydata['createdate']=date("Y-m-d H:i:s");
           $this->db->db_set($arraydata,'tb_product_userpay');
           
           
           $sql='select 
IF (tb_product_setting.shopname is NULL,tb_user.displayname,tb_product_setting.shopname) as displayname,
tb_user.username,
IF (tb_product_setting.orderprefix is NULL,\'\',tb_product_setting.orderprefix) as orderprefix,
IF (tb_user.email,tb_user.email,tb_user.emailfacebook) as email

 from tb_user 

 LEFT JOIN tb_product_setting ON tb_user.userid = tb_product_setting.createby

 where tb_user.userid='.$this->post['shopid'];
            $arraysetting=$this->db->db_set_1recordrow($sql);
           
           
           $msgto='payment your order. (Order Id:'.$arraysetting['orderprefix'].$this->post['orderid'].')';

          
           $userid=$this->post['shopid'];
           $arraydataset['userid']=$userid;
           $arraydataset['createby']=$userdata['userid'];
           $arraydataset['conid']=0;
           $arraydataset['smsgid']=$this->savesupermsg($msgto,0,$this->post['orderid'],2);
           $notiid[$userid]=$this->savenotificationlist($arraydataset);
           
           
           
           }
           
           }
           
           }
           
           function saveordertocart()
             {
           
           if($this->userdata['oauth']&&$this->post['userid']&&count($this->post['suborderlist'])&&$this->post['suborderlist'])
           {
           $userdata=$this->getuserbyoauth($this->userdata['oauth']);
           
          
           
           if(count($this->post['suborderlist']))
           {
           foreach($this->post['suborderlist'] as $valuesuborder)
           {
           $sql='select tb_plugins_pricefull.point,tb_plugins_pricefull.realprice,userpoint,priceid,unlimit,amount from tb_plugins_pricefull where tb_plugins_pricefull.productid='.$valuesuborder['productid'].'';
           $arraypoint=$this->db->db_set_1recordrow($sql);
           
           if($valuesuborder['suborderid'])
           {
           $sql2='select tb_product_suborder.suborderid from tb_product_suborder where tb_product_suborder.suborderid='.$valuesuborder['suborderid'];
           
           $arraypoint2=$this->db->db_set_1recordrow($sql2);
           
           if($arraypoint2['suborderid'])
           {
           
           
           }else
           {
           
           $this->arraydata['error'][]=46;
           exit;
           
           }
           
           }
           
           
           if($arraypoint['priceid'])
           {
           
           if($arraypoint['unlimit']=='0')
           {
           $amount=intval($arraypoint['amount']);
           if($amount<intval($valuesuborder['qty']))
           {
           $this->arraydata['error'][]=44;
           exit;
           }
           
           
           }
           
           
           
         
      
           
           }else
           {
           $this->arraydata['error'][]=42;
           exit;
           
           }
           
           }
           }
           
           $arrayorder['sumall']=$this->post['sumall'];
           $arrayorder['userid']=$userdata['userid'];
           $arrayorder['updateby']=$this->post['userid'];
           $arrayorder['updatedate']=date('Y-m-d H:i:s');
           $arrayorder['status']=1;
           $arrayorder['cart']=1;
           
           if($this->post['tfid'])
           {
           $arrayorder['tfid']=$this->post['tfid'];
           }
           
           
           if($this->post['tspoid'])
           {
           $arrayorder['tspoid']=$this->post['tspoid'];
           }
           
           $arrayorder['cartstatus']=1;
           
           if($this->post['orderid'])
           {
           $orderid=$this->post['orderid'];
           $this->db->db_set($arrayorder,'tb_product_order',' orderid='.$orderid);
           
           
           }
           else
           {
           
           $arrayorder['createdate']=date('Y-m-d H:i:s');
           $arrayorder['createby']=$this->post['userid'];
           $this->db->db_set($arrayorder,'tb_product_order');
           $orderid=$this->db->db_get_last_number();
           
           
           
           }
           
            
           if(count($this->post['suborderlist']))
           {
           foreach($this->post['suborderlist'] as $valuesuborder)
           {
           if($valuesuborder['suborderid'])
           {
           
           }else
           {
           
           $arraysuborder=array();
           $arraysuborder['productid']=$valuesuborder['productid'];
           $arraysuborder['credit']=0;
           $arraysuborder['point']=0;
           $arraysuborder['count']=$valuesuborder['qty'];
           $arraysuborder['orderid']=$orderid;
           $arraysuborder['price']=$valuesuborder['price'];
           $arraysuborder['note']=$this->post['note'];
           $this->db->db_set($arraysuborder,'tb_product_suborder');
           
           $this->changeproductstock($valuesuborder['qty'],$valuesuborder['productid']);
           
           }
           
           
           }
           
           }
           
           if(count($this->post['discountlist']))
           {
           foreach($this->post['discountlist'] as $valuediscount)
           {
           
           
            $arraysuborder=array();
           $arraysuborder['productid']=$valuediscount['productid'];
           $arraysuborder['credit']=0;
           $arraysuborder['point']=0;
           $arraysuborder['count']=1;
           $arraysuborder['orderid']=$orderid;
           $arraysuborder['price']=0;
           $arraysuborder['discount']=$valuediscount['discount'];
           $arraysuborder['title']=$valuediscount['title'];
           $arraysuborder['note']=$this->post['note'];
           $this->db->db_set($arraysuborder,'tb_product_suborder');
           
           
           }
           
           }
           
           
           $this->sendemailbyorderid($orderid);
           
           
           
           
           
           $this->arraydata['data']['orderid']=$orderid;
           
           
           
           
             $sql='SELECT * FROM `tb_product_order` where tb_product_order.orderid='.$orderid;
            $arrayproduct=$this->db->db_set_1recordrow($sql);
            
             $sql='select 
IF (tb_product_setting.shopname is NULL,tb_user.displayname,tb_product_setting.shopname) as displayname,
tb_user.username,
IF (tb_product_setting.orderprefix is NULL,\'\',tb_product_setting.orderprefix) as orderprefix,
IF (tb_user.email,tb_user.email,tb_user.emailfacebook) as email

 from tb_user 

 LEFT JOIN tb_product_setting ON tb_user.userid = tb_product_setting.createby

 where tb_user.userid='.$arrayproduct['createby'];
            $arraysetting=$this->db->db_set_1recordrow($sql);


           $msgto='order your product. (Order Id:'.$arraysetting['orderprefix'].$orderid.')';

          
           $userid=$arrayproduct['createby'];
           $arraydataset['userid']=$userid;
           $arraydataset['createby']=$_COOKIE['userid'];
           $arraydataset['conid']=0;
           $arraydataset['smsgid']=$this->savesupermsg($msgto,0,$orderid,1);
           $notiid[$userid]=$this->savenotificationlist($arraydataset);
    
            $arraydatanow[]=$userid;


 $this->sendtonotification($arraydatanow,$msgto,$notiid);
           
           
           
           }
           else
           {
           $this->arraydata['error'][]=47;
           }
           
           
           }
           
           
           
           function checkupdatemessage()
           {
           if($this->userdata['oauth']&&$this->post['userid'])
           {
           $userdata=$this->getuserbyoauth($this->userdata['oauth']);
           if($userdata['userid'])
           {
           $this->arraydata['data']['checknewmessage']=$this->checklastmsg($this->post['userid'],$this->userdata['oauth'],$this->post['msgid']);
           
           
           }
           
           }
           
           
           }
           function gettranferdata()
           {
           if($this->get['userid'])
           {
           $sql='SELECT
tb_product_transfer_bank.bankname,
tb_product_transfer_type.typename,
tb_product_transfer.branch,
tb_product_transfer.accname,
tb_product_transfer.accnumber,
tb_product_transfer.tfid
FROM
tb_product_transfer
INNER JOIN tb_product_transfer_bank ON tb_product_transfer.bankid = tb_product_transfer_bank.bankid
INNER JOIN tb_product_transfer_type ON tb_product_transfer.actypeid = tb_product_transfer_type.actypeid
where tb_product_transfer.createby='.$this->get['userid'].' and tb_product_transfer.delete=0
';

$arraytranferdata=$this->db->db_set_recordset($sql);
$this->arraydata['data']['data']=$arraytranferdata;


$sql='SELECT
tb_user.username,
IF (tb_product_setting.shopname is NULL,tb_user.displayname,tb_product_setting.shopname) as displayname,
IF (tb_product_setting.orderprefix is NULL,\'\',tb_product_setting.orderprefix) as orderprefix,
tb_user.simgmid
FROM
tb_user
LEFT JOIN tb_product_setting ON tb_user.userid = tb_product_setting.createby
where tb_user.userid='.$this->get['userid'].'
';
$arraytranferdata2=$this->db->db_set_1recordrow($sql);
$arraytranferdata2['img']=$this->getimagebyimgmid($arraytranferdata2['simgmid']);
$this->arraydata['data']['user']=$arraytranferdata2;





           }
           
           
           }
           
           function testka()
           {
           
           define("VAR_NAME","test");
// assigning value
${VAR_NAME} = "value";
// getting value back
echo VAR_NAME; 

exit;
           $url = "https://ajax.googleapis.com/ajax/services/search/web?v=1.0&"
    . "q=Paris%20Hilton&userip=USERS-IP-ADDRESS";

// sendRequest
// note how referer is set manually
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_REFERER,'v19.dmconnex.com');
$body = curl_exec($ch);
curl_close($ch);

// now, process the JSON string
$json = json_decode($body);

echo "<pre>";
print_r($json);
echo "</pre>;";

           }
           
           
           function testdatarow()
           {
           
           $this->arraydata['data']=$_POST;
           
           
           }
           
           
           function getlangall()
           {
           
                    $this->arraydata['data']=parent::getlangall();
           
           }
           
           function login()
           {
           if( (($this->post['email']||$this->post['username'])&&$this->post['password'])||$this->post['oauth']||$this->post['facebookid']  )
           {

           if($this->post['oauth'])
           { 
           $datauser=$this->getuserbyoauth($this->post['oauth']);
           
           
           }else if(is_numeric($this->post['facebookid']))
           {
           
           $datauser=$this->loginfacebook($this->post['facebookid'],$this->post['email'],$this->post['firstname'],$this->post['lastname'],$this->post['gender']);

           
           }
           else
           {
           
           $email=$this->post['email'];
           $username=$this->post['username'];
           $password=$this->post['password'];
           $datauser=$this->loginuser($username,$email,$password);
           

           }
           
           
           
           
           if($datauser['userid']&&$datauser['status']==1)
           {
           
           
           if($this->post['token']&&$this->post['uuid'])
           {
           
           $this->savetoken($datauser['userid'],$this->post['token'],$this->post['uuid']);
           
           }
                      $domain='';
                      if(NameDmconnex=="Canonlife"){
                      $url='http://'.$_SERVER['HTTP_HOST'];
                      $domain='.'.get_domain($url);
                      }
           
           
           
           if($this->post['rememberme']||is_numeric($this->post['facebookid']))
                {
                $time=time()+3600000;
                }else
                {
                $time=0;
                }
                
                setcookie("timelimit",$time, $time, "/",$domain);
                
                if($this->post['pos'])
                {
                
                if($datauser['roleid']=='3'||$datauser['roleid']=='4'||$datauser['roleid']=='5')
                {
                setcookie('poslogin',1, 0, "/",$domain);
                }
                
                
                }
                
                
                
           foreach($datauser as $keyuser =>$valueuser)
           {
                   if("imgmid"==$keyuser)
                   {
                   
                        $imgarray=$this->getimagebyimgmid($valueuser);

                        setcookie("imguser",$imgarray['newpath'], $time, "/",$domain);
                        setcookie("width",$imgarray['width'], $time, "/",$domain);
                        setcookie("height",$imgarray['height'], $time, "/",$domain);
                        $this->arraydata['data']['imguser']=$imgarray;
                   
                   }else if("simgmid"==$keyuser)
                   {
                        $imgarray=$this->getimagebyimgmid($valueuser);

                        setcookie("simguser",$imgarray['newpath'], $time, "/",$domain);
                        setcookie("thumbwidth",$imgarray['width'], $time, "/",$domain);
                        setcookie("thumbheight",$imgarray['height'], $time, "/",$domain);
                        $this->arraydata['data']['thumbuser']=$imgarray;
                   
                   
                   }
                   
                   
                       $this->arraydata['data'][$keyuser]=$valueuser;
                       setcookie($keyuser,$valueuser, $time, "/",$domain);
              
           
           
           
           }
           


           
           
           }
           else
           {
           $this->arraydata['error'][]=3;
           
           }
           
           
           }else
           {
           if(count($this->post))
           {
      //     foreach($this->post as $key => $value) {
//          
//            $data['test']=$key.'->'.$value;
//            $this->db->db_set($data,'tb_log');
//          
//          
//          }
          }
          
        
           
           
           
           $this->arraydata['error'][]=4;
           
           }
         
           
           }
           
           function getdomainset()
           {

           
           }
           
           function logout()
           {
                      $domain='';
                      if(NameDmconnex=="Canonlife"){
                      $url='http://'.$_SERVER['HTTP_HOST'];
                      $domain='.'.get_domain($url);
                      }
           if(count($this->userdata))
           {
           $time=time()-3600000;
           foreach($this->userdata as $keyuser => $valueuser)
           {
           
           setcookie($keyuser,"", $time, "/");
           
           } 
           
           foreach($_COOKIE  as $keyuser => $valueuser)   
           {
           
           setcookie($keyuser,"", $time, "/",$domain);   
           } 
                
           }

           
           if($this->get['noredirect']!=1)
           {
           
             $linkto=baseinfo;
             if($this->get['linkto'])
             {
             $linkto=baseinfo.$this->get['linkto'];
             }
           
             alert('',baseinfo);
            
           }
           
           if($this->post['token'])
           {
           
           $this->deletetoken($this->post['token']);
           
           }
             
           
           }
           
           function getpassword()
           {
           $password="123456";
           $md5password=md5($password.'-123456');
           
           echo $md5password;
           
           }
           
           function forgetpassword()
           {
           
           if($this->post['email'])
           {
           
           $sql=" select userid,username from tb_user where email='".$this->post['email']."'";
           $arrayuser=$this->db->db_set_recordset($sql);
           if($arrayuser[0]['userid'])
           {
           $newpassword=substr(md5(mktime().$arrayuser[0]['username'].$arrayuser[0]['email']),0,10);
         //  echo $newpassword;
           $arraydata['password']=md5($newpassword.'-123456');
           
           $this->db->db_set($arraydata,"tb_user"," userid=".$arrayuser[0]['userid']);
           
           
           require_once(pluginpath.'/phpmailer/class.config.php'); // uri
           
           $mail = new ConfigMail();
           //$mail->setFrom("s_chanyut@hotmail.com","Bird Kung");
           $mail->setTo($this->post['email'],$arrayuser[0]['username']);
           $mail->setContent('We send new password to your email already , Password is '.trim($newpassword).'<br><a href="'.baseinfo.'" target="_blank">'.baseinfo.'</a>');
           $mail->setSubject("Send New Password From ".NameDmconnex);
           $mail->sendTo();
         //  $this->arraydata['password']=$newpassword;
           
           }else
           {
           $this->arraydata['error'][]=5;
           
           }
           }else
           {
           
           $this->arraydata['error'][]=4;
           
           }
           
           }
           
           function checkphpversion()
           {
           phpinfo();
           
           }
           
           function signup()
           {
           
           if($this->post['username']&&$this->post['email']&&$this->post['password'])
           {
           
           $username=$this->post['username'];
           $check1=$this->checkusername($username);
           
           $email=$this->post['email'];
           $check2=$this->checkemail($email);
          
           if($check1==1&&$check2==1)
           {
           
           $userArray['username']=$username;
           $userArray['displayname']=$username;
           $userArray['email']=$email;
           $md5password=md5($this->post['password'].'-123456');
           $userArray['password']=$md5password;
           $userArray['oauth']=md5(mktime().$md5password);
           
           if($this->post['uuid'])
           {
           $userArray['status']=1;
           }
           
           
           if(isset($this->post['recaptcha']))
           {
               require_once(pluginpath.'/recaptcha/recaptchalib.php'); // uri
               $privatekey='6Lcy6ukSAAAAAFv-n9NfJmDDOTs13p6jvMWFshiX';
               $resp = recaptcha_check_answer ($privatekey,
                                        $_SERVER["REMOTE_ADDR"],
                                        $this->post["recaptchac"],
                                        $this->post["recaptcha"]);
                                        
                                        
          if ($resp->is_valid) {
              //  echo "You got it!";
              $userArray['status']=1;
        } else {
            $this->arraydata['error'][]=38;
            exit;
                # set the error code so that we can display it
             //   $error = $resp->error;
        }
               
           }
           
           
           
           $userid=$this->saveregister($userArray,1);
          // $this->savescoredata($userid,2);
           $this->savegamenictaionbygxcid($userid,2);
           
           if(isset($this->post['recaptcha']))
           {
               $this->login();
               
           }else
           {
           if($this->post['uuid'])
           {    
           echo $userArray['oauth'];
           $this->arraydata['data']['oauth']=$userArray['oauth'];
           }else
           {
           require_once(pluginpath.'/phpmailer/class.config.php'); // uri
           
           $mail = new ConfigMail();
           //$mail->setFrom("s_chanyut@hotmail.com","Bird Kung");
           $mail->setTo($email,$username);
           $mail->setContent(' Action Required to Activate Membership for  <br> <a href="'.baseinfo.'/ajax/confirmuser?oauth='.$userArray['oauth'].'&nojson=1" target="_blank">Click here</a>');
           $mail->setSubject("Confirm New User From ".NameDmconnex);
           $mail->sendTo();
           }
               
           }
           
           
           
           
           }else
           {
           if($check1!=1)$this->arraydata['error'][]=$check1;
           if($check2!=1)$this->arraydata['error'][]=$check2;

           
           }
           
           
           
           
           }else
           {
           $this->arraydata['error'][]=4;
           
           }
           
           }
           
           function savecontact()
           {
           if($this->post['namecontact']&&$this->post['emailcontact']&&$this->post['titlecontact']&&$this->post['recaptcha'])
           {
           
           
               require_once(pluginpath.'/recaptcha/recaptchalib.php'); // uri
               $privatekey='6Lcy6ukSAAAAAFv-n9NfJmDDOTs13p6jvMWFshiX';
               $resp = recaptcha_check_answer ($privatekey,
                                        $_SERVER["REMOTE_ADDR"],
                                        $this->post["recaptchac"],
                                        $this->post["recaptcha"]);
                                        
                                        
              if ($resp->is_valid) {
              //  echo "You got it!";
              
              $arraydata['namecontact']=$this->post['namecontact'];
              $arraydata['emailcontact']=$this->post['emailcontact'];
              $arraydata['titlecontact']=$this->post['titlecontact'];
              $arraydata['messagecontact']=$this->post['messagecontact'];
              $arraydata['createdate']=date("Y-m-d H:i:s");
              $this->db->db_set($arraydata,'tb_contact');
              
              
              
              
           require_once(pluginpath.'/phpmailer/class.config.php'); // uri
           
           $mail = new ConfigMail();
           $mail->setFrom($this->post['emailcontact'],$this->post['namecontact']);
           
           if (!defined('emailcontact')) {
    $mail->setTo(Username,NameDmconnex);
}   else
{
$mail->setTo(emailcontact,NameDmconnex);

}
           
           
           
           $mail->setContent('Title '.$this->post['titlecontact'].' <br> Description '.$this->post['messagecontact'].' ');
           $mail->setSubject("Contact From Customer ".$this->post['namecontact']);
           $mail->sendTo();
              
              
              
              } else {
              $this->arraydata['error'][]=38;
              exit;
                # set the error code so that we can display it
             //   $error = $resp->error;
             }
             
             
           
           
           }else
           {
           $this->arraydata['error'][]=4;
           
           }
           
           
           }
           
           

           function getstatpos()
            {
            
           $strwhere='';
           $day=0;
           $week=0;
            switch ($this->get['status']) {
                case 1:
                $day=1;
                $week=1;
                $date=date("Y-m-d");
                $strwhere=' and tb_product_order.createdate BETWEEN "'.date("Y-m-d 00:00:00").'" AND "'.date("Y-m-d 23:59:59").'" ';
                break;
                
                case 2:
                $week=1;
                $arrayset=x_week_range2(date("Y-m-d"));
                $strwhere=' and tb_product_order.createdate BETWEEN "'.$arrayset[0].'" AND "'.$arrayset[1].'" ';
                break;
                
                case 3:
                $strwhere=' and tb_product_order.createdate BETWEEN "'.date("Y-m-1 00:00:00").'" AND "'.date("Y-m-t 23:59:59").'" ';
                break;
                

                
                case 5:
                
                if($this->get['startdate']&&$this->get['enddate'])
                {
                list($s1,$s2,$s3)=explode("/",$this->get['startdate']);
                list($e1,$e2,$e3)=explode("/",$this->get['enddate']);
                $strwhere=' and tb_product_order.createdate BETWEEN "'.($s3."-".$s2."-".$s1." 00:00:00").'" AND "'.($e3."-".$e2."-".$e1." 23:59:59").'" ';
                if($this->get['startdate']==$this->get['enddate'])
                {
                $date=date("Y-m-d");
                $day=1;
                }
                }
                
                
                
                break;
            }



            
            $sql='SELECT
IF(SUM(tb_product_order.sumall) IS NULL,0,SUM(tb_product_order.sumall))  as benefit,

(SELECT
count(tb_product_order.orderid) as countorder
FROM
tb_product_order
where tb_product_order.`status`=2 '.$strwhere.') as countorder,

(SELECT
count(tb_product_suborder.productid) as countitemsold
FROM
tb_product_order
INNER JOIN tb_product_suborder ON tb_product_order.orderid = tb_product_suborder.orderid
where tb_product_order.`status`=2 and tb_product_suborder.discount=0 and tb_product_suborder.productid !=0 '.$strwhere.') as countitemsold,

(SELECT
count(tb_product_suborder.productid) as countpromotion
FROM
tb_product_order
INNER JOIN tb_product_suborder ON tb_product_order.orderid = tb_product_suborder.orderid
where tb_product_order.`status`=2 and tb_product_suborder.price=0 and tb_product_suborder.productid !=0 '.$strwhere.') as countpromotion

FROM
tb_product_order
where tb_product_order.`status`=2 '.$strwhere.'
';
                $arraystat=$this->db->db_set_1recordrow($sql);
                
                
                // Best Seller


                $sql='select tb_c.title,IF(tb_c.countdata IS NULL,0,tb_c.countdata) as countdata FROM 
(
select  tb_product.title,
(select sum(tb_product_suborder.count) as countdata 
 FROM tb_product_order 
 INNER JOIN tb_product_suborder ON tb_product_order.orderid = tb_product_suborder.orderid 
 where tb_product_order.`status`=2 and tb_product_suborder.discount=0 and tb_product_suborder.productid =tb_product.productid  '.$strwhere.') as countdata FROM 
tb_product
INNER JOIN tb_plugins_price ON tb_product.productid = tb_plugins_price.productid
where tb_product.delete=0 
ORDER BY countdata desc) tb_c
where tb_c.countdata!=0
ORDER BY countdata desc
';

                $arraydata=$this->db->db_set_recordset($sql);
                $arraysum=array();

                if(count($arraydata))
                {
                foreach($arraydata as $valueseller)
                {
                $arraysum[]=intval($valueseller['countdata']);
                
                }
                $sumdata=array_sum($arraysum);
                 if($sumdata==0)
                {
                $sumdata=1;
                }
                $k=0;
                foreach($arraydata as $valueseller)
                {
                $arraydata[$k]['countdata']=intval($arraydata[$k]['countdata']);
                $arraydata[$k]['show']=intval($arraydata[$k]['countdata']).' Items';
                $arraydata[$k]['percent']=number_format(((100*intval($valueseller['countdata']))/$sumdata), 2, '.', '').'%';
                
                $arraydata[$k]['color']= '#'.strtoupper(dechex(rand(0,10000000)));
                $arraydata[$k]['category']=$arraydata[$k]['title'];
                $arraydata[$k]['value']=floatval(number_format(((100*intval($valueseller['countdata']))/$sumdata), 2, '.', ''));
                $k++;
                }
                }
                
                $arraystat['stat']['bestseller']['data']=$arraydata;
                $arraystat['stat']['bestseller']['name']="Best Seller";
                
                
              // Top Promotion
              
//              $sql='select  tb_product.title,
//(select count(tb_product_suborder.suborderid) as countdata 
// FROM tb_product_order 
// INNER JOIN tb_product_suborder ON tb_product_order.orderid = tb_product_suborder.orderid 
// where tb_product_order.`status`=2 and tb_product_suborder.discount!=0 and tb_product_suborder.productid =tb_product.productid '.$strwhere.' ) as countdata FROM 
//tb_product
//INNER JOIN tb_plugins_discount ON tb_product.productid = tb_plugins_discount.productid 
//where tb_product.delete=0 
//ORDER BY countdata desc';


                $sql='select tb_c.title,IF(tb_c.countdata IS NULL,0,tb_c.countdata) as countdata FROM 
(
select  tb_product.title,
(select sum(tb_product_suborder.count) as countdata 
 FROM tb_product_order 
 INNER JOIN tb_product_suborder ON tb_product_order.orderid = tb_product_suborder.orderid 
 where tb_product_order.`status`=2 and tb_product_suborder.discount!=0 and tb_product_suborder.productid =tb_product.productid  '.$strwhere.') as countdata FROM 
tb_product
INNER JOIN tb_plugins_discount ON tb_product.productid = tb_plugins_discount.productid
where tb_product.delete=0 
ORDER BY countdata desc) tb_c';


                $arraydata=$this->db->db_set_recordset($sql);
                $arraysum=array();

                if(count($arraydata))
                {
                foreach($arraydata as $valueseller)
                {
                $arraysum[]=intval($valueseller['countdata']);
                
                }
                $sumdata=array_sum($arraysum);
                if($sumdata==0)
                {
                $sumdata=1;
                }
                
                $k=0;
                foreach($arraydata as $valueseller)
                {
                $arraydata[$k]['countdata']=intval($arraydata[$k]['countdata']);
                $arraydata[$k]['show']=intval($arraydata[$k]['countdata']).' Times';
                $arraydata[$k]['percent']=number_format(((100*intval($valueseller['countdata']))/$sumdata), 2, '.', '').'%';
                
                $arraydata[$k]['color']= '#'.strtoupper(dechex(rand(0,10000000)));
                $arraydata[$k]['category']=$arraydata[$k]['title'];
                $arraydata[$k]['value']=floatval(number_format(((100*intval($valueseller['countdata']))/$sumdata), 2, '.', ''));
                
                $k++;
                }
                }
                
                $arraystat['stat']['bestpro']['data']=$arraydata;
                $arraystat['stat']['bestpro']['name']="Top Promotion";   
                
                if($day)
                {
                
                $sql="SELECT
'00:00 AM - 03:00 AM' as title,count(tb_product_order.orderid) as countdata
FROM
tb_product_order
where tb_product_order.`status`=2 and tb_product_order.createdate BETWEEN '".$date." 00:00:00' AND '".$date." 03:00:00'

UNION

SELECT
'03:00 AM - 06:00 AM' as title,count(tb_product_order.orderid) as countdata
FROM
tb_product_order
where tb_product_order.`status`=2 and tb_product_order.createdate BETWEEN '".$date." 03:00:01' AND '".$date." 06:00:00'


UNION

SELECT
'06:00 AM - 09:00 AM' as title,count(tb_product_order.orderid) as countdata
FROM
tb_product_order
where tb_product_order.`status`=2 and tb_product_order.createdate BETWEEN '".$date." 06:00:01' AND '".$date." 09:00:00'

UNION

SELECT
'09:00 AM - 12:00 AM' as title,count(tb_product_order.orderid) as countdata
FROM
tb_product_order
where tb_product_order.`status`=2 and tb_product_order.createdate BETWEEN '".$date." 09:00:01' AND '".$date." 12:00:00'

UNION

SELECT
'12:00 AM - 03:00 PM' as title,count(tb_product_order.orderid) as countdata
FROM
tb_product_order
where tb_product_order.`status`=2 and tb_product_order.createdate BETWEEN '".$date." 12:00:01' AND '".$date." 15:00:00'


UNION

SELECT
'03:00 PM - 06:00 PM' as title,count(tb_product_order.orderid) as countdata
FROM
tb_product_order
where tb_product_order.`status`=2 and tb_product_order.createdate BETWEEN '".$date." 15:00:01' AND '".$date." 18:00:00'

UNION

SELECT
'06:00 PM - 09:00 PM' as title,count(tb_product_order.orderid) as countdata
FROM
tb_product_order
where tb_product_order.`status`=2 and tb_product_order.createdate BETWEEN '".$date." 18:00:01' AND '".$date." 21:00:00'

UNION

SELECT
'09:00 PM - 12:00 PM' as title,count(tb_product_order.orderid) as countdata
FROM
tb_product_order
where tb_product_order.`status`=2 and tb_product_order.createdate BETWEEN '".$date." 21:00:01' AND '".$date." 23:59:59'
";
                
                $arraydata=$this->db->db_set_recordset($sql);
                $arraysum=array();

                if(count($arraydata))
                {
                foreach($arraydata as $valueseller)
                {
                $arraysum[]=intval($valueseller['countdata']);
                
                }
                $sumdata=array_sum($arraysum);
                 if($sumdata==0)
                {
                $sumdata=1;
                }
                $k=0;
                foreach($arraydata as $valueseller)
                {
                $arraydata[$k]['countdata']=intval($arraydata[$k]['countdata']);
                $arraydata[$k]['show']=intval($arraydata[$k]['countdata']).' Orders';
                $arraydata[$k]['percent']=number_format(((100*intval($valueseller['countdata']))/$sumdata), 2, '.', '').'%';
                
                $arraydata[$k]['color']= '#'.strtoupper(dechex(rand(0,10000000)));
                $arraydata[$k]['category']=$arraydata[$k]['title'];
                $arraydata[$k]['value']=floatval(number_format(((100*intval($valueseller['countdata']))/$sumdata), 2, '.', ''));
                
                $k++;
                }
                }
                
                $arraystat['stat']['hottime']['data']=$arraydata;
                $arraystat['stat']['hottime']['name']="Hot Time of Day";  
                
                
                }
                
                if($week)
                {
            $daynum['Monday'] = date("Y-m-d", strtotime("monday  this week"));
            $daynum['Tuesday'] = date("Y-m-d", strtotime("tuesday  this week"));
            $daynum['Wednesday'] = date("Y-m-d", strtotime("wednesday  this week"));
            $daynum['Thursday'] = date("Y-m-d", strtotime("thursday  this week"));
            $daynum['Friday'] = date("Y-m-d", strtotime("friday  this week"));
            $daynum['Saturday'] = date("Y-m-d", strtotime("saturday  this week"));
            $daynum['Sunday'] = date("Y-m-d", strtotime("sunday  this week"));
            

            foreach($daynum as $keynum => $valueday)
            {
            $sqlarray[]="SELECT
'".$keynum."' as title,count(tb_product_order.orderid) as countdata
FROM
tb_product_order
where tb_product_order.`status`=2 and tb_product_order.createdate BETWEEN '".$valueday." 00:00:00' AND '".$valueday." 23:59:59' ";
            
            }
            
            $sql=join(" UNION ",$sqlarray);
            
            $arraydata=$this->db->db_set_recordset($sql);
                $arraysum=array();

                if(count($arraydata))
                {
                foreach($arraydata as $valueseller)
                {
                $arraysum[]=intval($valueseller['countdata']);
                
                }
                $sumdata=array_sum($arraysum);
                 if($sumdata==0)
                {
                $sumdata=1;
                }
                $k=0;
                foreach($arraydata as $valueseller)
                {
                $arraydata[$k]['countdata']=intval($arraydata[$k]['countdata']);
                $arraydata[$k]['show']=intval($arraydata[$k]['countdata']).' Orders';
                $arraydata[$k]['percent']=number_format(((100*intval($valueseller['countdata']))/$sumdata), 2, '.', '').'%';
                
                $arraydata[$k]['color']= '#'.strtoupper(dechex(rand(0,10000000)));
                $arraydata[$k]['category']=$arraydata[$k]['title'];
                $arraydata[$k]['value']=floatval(number_format(((100*intval($valueseller['countdata']))/$sumdata), 2, '.', ''));
                $k++;
                }
                }
                
                $arraystat['stat']['hotweek']['data']=$arraydata;
                $arraystat['stat']['hotweek']['name']="Hot Day of Week";  
            
                
                }
                
                
                $sql="SELECT * FROM (SELECT
'Female' as title,count(tb_product_question_relate.orderid) as countdata
FROM
tb_product_question
INNER JOIN tb_product_question_relate ON tb_product_question.questionid = tb_product_question_relate.questionid
INNER JOIN tb_product_order ON tb_product_order.orderid=tb_product_question_relate.orderid
where tb_product_question.gender=2 ".$strwhere." 

UNION 


SELECT
'Male' as title,count(tb_product_question_relate.orderid) as countdata
FROM
tb_product_question
INNER JOIN tb_product_question_relate ON tb_product_question.questionid = tb_product_question_relate.questionid
INNER JOIN tb_product_order ON tb_product_order.orderid=tb_product_question_relate.orderid
where tb_product_question.gender=1 ".$strwhere.') t_c order by countdata desc';


                $arraydata=$this->db->db_set_recordset($sql);
                $arraysum=array();

                if(count($arraydata))
                {
                foreach($arraydata as $valueseller)
                {
                $arraysum[]=intval($valueseller['countdata']);
                
                }
                $sumdata=array_sum($arraysum);
                 if($sumdata==0)
                {
                $sumdata=1;
                }
                $k=0;
                foreach($arraydata as $valueseller)
                {
                $arraydata[$k]['countdata']=intval($arraydata[$k]['countdata']);
                $arraydata[$k]['show']=intval($arraydata[$k]['countdata']).' Orders';
                $arraydata[$k]['percent']=number_format(((100*intval($valueseller['countdata']))/$sumdata), 2, '.', '').'%';
                
                $arraydata[$k]['color']= '#'.strtoupper(dechex(rand(0,10000000)));
                $arraydata[$k]['category']=$arraydata[$k]['title'];
                $arraydata[$k]['value']=floatval(number_format(((100*intval($valueseller['countdata']))/$sumdata), 2, '.', ''));
                $k++;
                }
                }
                
                $arraystat['stat']['gen']['data']=$arraydata;
                $arraystat['stat']['gen']['name']="Customer Characteristics";  
                
                
                
                
                $sql="
SELECT * FROM(
SELECT
'Kid' as title,count(tb_product_question_relate.orderid) as countdata
FROM
tb_product_question
INNER JOIN tb_product_question_relate ON tb_product_question.questionid = tb_product_question_relate.questionid
INNER JOIN tb_product_order ON tb_product_order.orderid=tb_product_question_relate.orderid
where tb_product_question.age=1 ".$strwhere."

UNION

SELECT
'Teen' as title,count(tb_product_question_relate.orderid) as countdata
FROM
tb_product_question
INNER JOIN tb_product_question_relate ON tb_product_question.questionid = tb_product_question_relate.questionid
INNER JOIN tb_product_order ON tb_product_order.orderid=tb_product_question_relate.orderid
where tb_product_question.age=2 ".$strwhere."

UNION

SELECT
'Adult' as title,count(tb_product_question_relate.orderid) as countdata
FROM
tb_product_question
INNER JOIN tb_product_question_relate ON tb_product_question.questionid = tb_product_question_relate.questionid
INNER JOIN tb_product_order ON tb_product_order.orderid=tb_product_question_relate.orderid
where tb_product_question.age=3 ".$strwhere."

UNION

SELECT
'Old' as title,count(tb_product_question_relate.orderid) as countdata
FROM
tb_product_question
INNER JOIN tb_product_question_relate ON tb_product_question.questionid = tb_product_question_relate.questionid
INNER JOIN tb_product_order ON tb_product_order.orderid=tb_product_question_relate.orderid
where tb_product_question.age=4 ".$strwhere." ) tb_c ORDER BY  tb_c.countdata desc";


                $arraydata=$this->db->db_set_recordset($sql);
                $arraysum=array();

                if(count($arraydata))
                {
                foreach($arraydata as $valueseller)
                {
                $arraysum[]=intval($valueseller['countdata']);
                
                }
                $sumdata=array_sum($arraysum);
                 if($sumdata==0)
                {
                $sumdata=1;
                }
                $k=0;
                foreach($arraydata as $valueseller)
                {
                $arraydata[$k]['countdata']=intval($arraydata[$k]['countdata']);
                $arraydata[$k]['show']=intval($arraydata[$k]['countdata']).' Orders';
                $arraydata[$k]['percent']=number_format(((100*intval($valueseller['countdata']))/$sumdata), 2, '.', '').'%';
                
                $arraydata[$k]['color']= '#'.strtoupper(dechex(rand(0,10000000)));
                $arraydata[$k]['category']=$arraydata[$k]['title'];
                $arraydata[$k]['value']=floatval(number_format(((100*intval($valueseller['countdata']))/$sumdata), 2, '.', ''));
                $k++;
                }
                }
                
                $arraystat['stat']['age']['data']=$arraydata;
                $arraystat['stat']['age']['name']="Customer Characteristics"; 
                
                
                
                $sql="SELECT
SUM(tb_product_order.sumall) as countdata,
(select IF (tb_user.displayname = '', tb_user.username,tb_user.displayname) as title FROM  tb_user where tb_user.userid=  tb_product_order.userid) as title
FROM
tb_product_order
where tb_product_order.userid!=0 and tb_product_order.`status`=2 ".$strwhere."
GROUP BY tb_product_order.userid
ORDER BY countdata desc
limit 0,20"; 


                $arraydata=$this->db->db_set_recordset($sql);
                $arraysum=array();

                if(count($arraydata))
                {
                foreach($arraydata as $valueseller)
                {
                $arraysum[]=intval($valueseller['countdata']);
                
                }
                $sumdata=array_sum($arraysum);
                 if($sumdata==0)
                {
                $sumdata=1;
                }
                $k=0;
                foreach($arraydata as $valueseller)
                {
                $arraydata[$k]['countdata']=intval($arraydata[$k]['countdata']);
                $arraydata[$k]['show']=intval($arraydata[$k]['countdata']).' Baht';
                $arraydata[$k]['percent']=number_format(((100*intval($valueseller['countdata']))/$sumdata), 2, '.', '').'%';
                
                $arraydata[$k]['color']= '#'.strtoupper(dechex(rand(0,10000000)));
                $arraydata[$k]['category']=$arraydata[$k]['title'];
                $arraydata[$k]['value']=floatval(number_format(((100*intval($valueseller['countdata']))/$sumdata), 2, '.', ''));
                $k++;
                }
                }
                
                $arraystat['stat']['member']['data']=$arraydata;
                $arraystat['stat']['member']['name']="Top Member";
                
                
                
                $sql="SELECT
'0 Baht - 100 Baht' as title,count(tb_product_order.orderid) countdata
FROM
tb_product_order
where tb_product_order.sumall BETWEEN 0 AND 100 ".$strwhere."

UNION 

SELECT
'101 Baht - 200 Baht' as title,count(tb_product_order.orderid) countdata
FROM
tb_product_order
where tb_product_order.sumall BETWEEN 101 AND 200 ".$strwhere."

UNION 

SELECT
'201 Baht - 300 Baht' as title,count(tb_product_order.orderid) countdata
FROM
tb_product_order
where tb_product_order.sumall BETWEEN 201 AND 300 ".$strwhere."

UNION 

SELECT
'301 Baht - 400 Baht' as title,count(tb_product_order.orderid) countdata
FROM
tb_product_order
where tb_product_order.sumall BETWEEN 301 AND 400 ".$strwhere."

UNION 

SELECT
'401 Baht - 500 Baht' as title,count(tb_product_order.orderid) countdata
FROM
tb_product_order
where tb_product_order.sumall BETWEEN 401 AND 500 ".$strwhere."


UNION 

SELECT
'501 Baht - 600 Baht' as title,count(tb_product_order.orderid) countdata
FROM
tb_product_order
where tb_product_order.sumall BETWEEN 501 AND 600 ".$strwhere."

UNION 

SELECT
'601 Baht - 700 Baht' as title,count(tb_product_order.orderid) countdata
FROM
tb_product_order
where tb_product_order.sumall BETWEEN 601 AND 700 ".$strwhere."

UNION 

SELECT
'701 Baht - 800 Baht' as title,count(tb_product_order.orderid) countdata
FROM
tb_product_order
where tb_product_order.sumall BETWEEN 701 AND 800 ".$strwhere."


UNION 

SELECT
'801 Baht - 900 Baht' as title,count(tb_product_order.orderid) countdata
FROM
tb_product_order
where tb_product_order.sumall BETWEEN 801 AND 900 ".$strwhere."


UNION 

SELECT
'More Than 900 Baht' as title,count(tb_product_order.orderid) countdata
FROM
tb_product_order
where tb_product_order.sumall >900 ".$strwhere;
                
                $arraydata=$this->db->db_set_recordset($sql);
                $arraysum=array();

                if(count($arraydata))
                {
                foreach($arraydata as $valueseller)
                {
                $arraysum[]=intval($valueseller['countdata']);
                
                }
                $sumdata=array_sum($arraysum);
                 if($sumdata==0)
                {
                $sumdata=1;
                }
                $k=0;
                foreach($arraydata as $valueseller)
                {
                $arraydata[$k]['countdata']=intval($arraydata[$k]['countdata']);
                $arraydata[$k]['show']=intval($arraydata[$k]['countdata']).' Orders';
                $arraydata[$k]['percent']=number_format(((100*intval($valueseller['countdata']))/$sumdata), 2, '.', '').'%';
                
                $arraydata[$k]['color']= '#'.strtoupper(dechex(rand(0,10000000)));
                $arraydata[$k]['category']=$arraydata[$k]['title'];
                $arraydata[$k]['value']=floatval(number_format(((100*intval($valueseller['countdata']))/$sumdata), 2, '.', ''));
                $k++;
                }
                }
                
                $arraystat['stat']['range']['data']=$arraydata;
                $arraystat['stat']['range']['name']="Payment Amount";
                
                
                $sql='SELECT tb_c.title,IF(tb_c.countdata IS NULL,0,tb_c.countdata) as countdata FROM (
SELECT
tb_tag.name as title,
(SELECT
sum(tb_product_suborder.count) as countdata
FROM
tb_relate_tag
INNER JOIN tb_product_suborder ON tb_relate_tag.productid = tb_product_suborder.productid
where  tb_relate_tag.tagid=tb_tag.tagid
) as countdata

FROM
tb_plugins_price
INNER JOIN (select productid,fid from  tb_product where tb_product.`delete`=0) tb_product ON tb_product.productid = tb_plugins_price.productid
INNER JOIN tb_relate_tag  ON tb_relate_tag.productid =tb_product.productid
INNER JOIN tb_tag  ON tb_tag.tagid =tb_relate_tag.tagid
where  tb_tag.system=1
group by tb_tag.tagid
order by tb_tag.createdate asc ) tb_c

order by countdata desc';



                $arraydata=$this->db->db_set_recordset($sql);
                $arraysum=array();

                if(count($arraydata))
                {
                foreach($arraydata as $valueseller)
                {
                $arraysum[]=intval($valueseller['countdata']);
                
                }
                $sumdata=array_sum($arraysum);
                 if($sumdata==0)
                {
                $sumdata=1;
                }
                $k=0;
                foreach($arraydata as $valueseller)
                {
                $arraydata[$k]['countdata']=intval($arraydata[$k]['countdata']);
                $arraydata[$k]['show']=intval($arraydata[$k]['countdata']).' Items';
                $arraydata[$k]['percent']=number_format(((100*intval($valueseller['countdata']))/$sumdata), 2, '.', '').'%';
                
                $arraydata[$k]['color']= '#'.strtoupper(dechex(rand(0,10000000)));
                $arraydata[$k]['category']=$arraydata[$k]['title'];
                $arraydata[$k]['value']=floatval(number_format(((100*intval($valueseller['countdata']))/$sumdata), 2, '.', ''));
                $k++;
                }
                }
                
                $arraystat['stat']['tag']['data']=$arraydata;
                $arraystat['stat']['tag']['name']="Best Seller Tag";
                
                
                
                
                
                $this->arraydata['data']=$arraystat;
                
                
            
            }
            
            
            function getstatposdata()
            {
            
           $strwhere='';
           $day=0;
           $week=0;
           if(!isset($this->get['status']))
           {
           $this->get['status']=1;
           
           }
                
                $sql='SELECT 
tb_tag.tagid,tb_tag.name
FROM
tb_plugins_price

INNER JOIN (select productid,fid from  tb_product where tb_product.`delete`=0 and tb_product.status=1) tb_product ON tb_product.productid = tb_plugins_price.productid
INNER JOIN tb_relate_tag  ON tb_relate_tag.productid =tb_product.productid
INNER JOIN tb_tag  ON tb_tag.tagid =tb_relate_tag.tagid
INNER JOIN tb_tag_show  ON tb_tag.tagid =tb_tag_show.tagid
group by tb_tag.tagid

UNION 

SELECT
tb_tag.tagid,tb_tag.name
FROM
tb_plugins_price
INNER JOIN (select productid,fid from  tb_product where tb_product.`delete`=0 and tb_product.status=1) tb_product ON tb_product.productid = tb_plugins_price.productid
INNER JOIN tb_relate_tag  ON tb_relate_tag.productid =tb_product.productid
INNER JOIN tb_tag  ON tb_tag.tagid =tb_relate_tag.tagid
where tb_tag.system=1
group by tb_tag.tagid';

                $arraydata=$this->db->db_set_recordset($sql);
                
                
                
                 $arraydatecheck=array();
                switch ($this->get['status']) {
                
                case 1:
                $arraydatecheck['col'][0][0]=date("D");
                $arraydatecheck['col'][1][0]=date("d M Y");
                $arraydatecheck['col'][2][0]=date("Y-m-d");
                

                $arraydatecheck['col'][3][0]=$this->getdataposcheckbydate(date("Y-m-d 00:00:00"),date("Y-m-d 23:59:59"));
                
                
                
                break;
                
                case 2:
                
                
                $arraydatecheck['col'][0][0]=date("D");
                $arraydatecheck['col'][1][0]=date("d M Y");
                $arraydatecheck['col'][2][0]=date("Y-m-d");
                $arraydatecheck['col'][3][0]=$this->getdataposcheckbydate(date("Y-m-d 00:00:00"),date("Y-m-d 23:59:59"));
                
                for($p=1;$p<7;$p++)
                {
                
                $arraydatecheck['col'][0][$p]=date("D",strtotime("-".$p." day"));
                $arraydatecheck['col'][1][$p]=date("d M Y",strtotime("-".$p." day"));
                $arraydatecheck['col'][2][$p]=date("Y-m-d",strtotime("-".$p." day"));
                $arraydatecheck['col'][3][$p]=$this->getdataposcheckbydate(date("Y-m-d 00:00:00",strtotime("-".$p." day")),date("Y-m-d 23:59:59",strtotime("-".$p." day")));
                
                }
                
                break;
                
                case 3:
                
                $arraydatecheck['col'][0][0]="";
                $arraydatecheck['col'][1][0]=date("F");
                $arraydatecheck['col'][2][0]=date("F");
                $arraydatecheck['col'][3][0]=$this->getdataposcheckbydate(date("Y-m-1 00:00:00"),date("Y-m-t 23:59:59"));
                
                break;
                
                case 5:
                
                if($this->get['startdate']&&$this->get['enddate'])
                {
                

                
                list($s1,$s2,$s3)=explode("/",$this->get['startdate']);
                list($e1,$e2,$e3)=explode("/",$this->get['enddate']);
              //  $dset=date_diff_bk(strtotime($s3.'-'.$s2.'-'.$s1), strtotime($e3.'-'.$e2.'-'.$e1));
              
              
              $date1 = new DateTime($s3.'-'.$s2.'-'.$s1);
              

$date2 = new DateTime($e3.'-'.$e2.'-'.$e1);

              


$diff = $date2->diff($date1)->format("%a");



        

                
                $arraydatecheck['col'][0][0]=date("D",strtotime($s3.'-'.$s2.'-'.$s1));
                $arraydatecheck['col'][1][0]=date("d M Y",strtotime($s3.'-'.$s2.'-'.$s1));
                $arraydatecheck['col'][2][0]=date("Y-m-d",strtotime($s3.'-'.$s2.'-'.$s1));
                $arraydatecheck['col'][3][0]=$this->getdataposcheckbydate(date("Y-m-d 00:00:00",strtotime($s3.'-'.$s2.'-'.$s1)),date("Y-m-d 23:59:59",strtotime($s3.'-'.$s2.'-'.$s1)));
                if($diff)
                {
                $diff=$diff+1;
                for($p=1;$p<$diff;$p++)
                {
                
                

                
                $arraydatecheck['col'][0][$p]=date("D",strtotime("+".$p." day",strtotime($s3.'-'.$s2.'-'.$s1)));
                $arraydatecheck['col'][1][$p]=date("d M Y",strtotime("+".$p." day",strtotime($s3.'-'.$s2.'-'.$s1)));
                $arraydatecheck['col'][2][$p]=date("Y-m-d",strtotime("+".$p." day",strtotime($s3.'-'.$s2.'-'.$s1)));
                $arraydatecheck['col'][3][$p]=$this->getdataposcheckbydate(date("Y-m-d 00:00:00",strtotime("+".$p." day",strtotime($s3.'-'.$s2.'-'.$s1))),date("Y-m-d 23:59:59",strtotime("+".$p." day",strtotime($s3.'-'.$s2.'-'.$s1))));
                }
                

                }
                
                
              
                
                
                
                
                
                }
                break;
                
                }
                $arraynewdata=array();
                $k=0;
                if(count($arraydata))
                {
                
                foreach($arraydata as $valuedata)
                {
                $arraynewdata[$k]['tagid']=$valuedata['tagid'];
                $arraynewdata[$k]['name']=$valuedata['name'];
                
                
                
                
                $arraynewdata[$k]['data']=array();
                
                $sql='SELECT
tb_plugins_price.price,
IF(tb_plugins_price.oprice = 0,tb_plugins_price.price,tb_plugins_price.oprice) oprice,
tb_product.title,
tb_plugins_price.priceid,
tb_product.productid
FROM
tb_relate_tag
INNER JOIN tb_product ON tb_relate_tag.productid = tb_product.productid
INNER JOIN tb_plugins_price ON tb_product.productid = tb_plugins_price.productid

where  tb_relate_tag.tagid='.$valuedata['tagid'];

             $data=$this->db->db_set_recordset($sql);
             $arrayset=array();
             $x=0;
             if(count($data))
             {
             foreach($data as $valuedata2)
             {
             
             
             
            switch ($this->get['status']) {
                case 1:
                $day=1;
                $week=1;
                $date=date("Y-m-d");
                $strwhere=' and tb_product_order.createdate BETWEEN "'.date("Y-m-d 00:00:00").'" AND "'.date("Y-m-d 23:59:59").'" ';
                
                $sql='
SELECT
IF(SUM(tb_product_suborder.count) IS NULL,0 ,SUM(tb_product_suborder.count)) as sum
FROM
tb_product_order
INNER JOIN tb_product_suborder ON tb_product_order.orderid = tb_product_suborder.orderid
where tb_product_suborder.productid='.$valuedata2['productid'].' '.$strwhere;



                $checkcount=$this->db->db_set_1recordrow($sql);
                $arrayset[0]=$checkcount['sum'];
                $data[$x]['countorder']=$arrayset;
                
                
                
                
              
                
                break;
                
                case 2:

                
                
                $kr=0;
                $arrayset=array();
                if(count($arraydatecheck['col'][2]))
                {
                foreach($arraydatecheck['col'][2] as $valued)
                {
                
                $strwhere=' and tb_product_order.createdate BETWEEN "'.$valued.' 00:00:00'.'" AND "'.$valued.' 23:59:59'.'" ';
                
                $sql='
SELECT
IF(SUM(tb_product_suborder.count) IS NULL,0 ,SUM(tb_product_suborder.count)) as sum
FROM
tb_product_order
INNER JOIN tb_product_suborder ON tb_product_order.orderid = tb_product_suborder.orderid
where tb_product_suborder.productid='.$valuedata2['productid'].' '.$strwhere;

                $checkcount=$this->db->db_set_1recordrow($sql);
                $arrayset[$kr]=$checkcount['sum'];
                
                
                $kr++;
                
                }
                
                
                }
                $data[$x]['countorder']=$arrayset;
                

                
                
                break;
                
                case 3:
                
                
                
                $strwhere=' and tb_product_order.createdate BETWEEN "'.date("Y-m-1 00:00:00").'" AND "'.date("Y-m-t 23:59:59").'" ';
                
                
                $sql='
SELECT
IF(SUM(tb_product_suborder.count) IS NULL,0 ,SUM(tb_product_suborder.count)) as sum
FROM
tb_product_order
INNER JOIN tb_product_suborder ON tb_product_order.orderid = tb_product_suborder.orderid
where tb_product_suborder.productid='.$valuedata2['productid'].' '.$strwhere;



                $checkcount=$this->db->db_set_1recordrow($sql);
                $arrayset[0]=$checkcount['sum'];
                $data[$x]['countorder']=$arrayset;
                
                
                break;
                

                
                case 5:
                
                 $kr=0;
                $arrayset=array();
                if(count($arraydatecheck['col'][2]))
                {
                foreach($arraydatecheck['col'][2] as $valued)
                {
                
                $strwhere=' and tb_product_order.createdate BETWEEN "'.$valued.' 00:00:00'.'" AND "'.$valued.' 23:59:59'.'" ';
                
                $sql='
SELECT
IF(SUM(tb_product_suborder.count) IS NULL,0 ,SUM(tb_product_suborder.count)) as sum
FROM
tb_product_order
INNER JOIN tb_product_suborder ON tb_product_order.orderid = tb_product_suborder.orderid
where tb_product_suborder.productid='.$valuedata2['productid'].' '.$strwhere;
                

                $checkcount=$this->db->db_set_1recordrow($sql);
                $arrayset[$kr]=$checkcount['sum'];
                
                
                $kr++;
                
                }
                
                
                }
                $data[$x]['countorder']=$arrayset;
                
                
                break;
            }

             
             
             
             $x++;
             
             }
             }
             
             
             
             
             $arraynewdata[$k]['data']=$data;
                
                
                
                
                
                $k++;
                
                
                
                
                
                
                }
                
                
                
                
                 }
                
               
                
                //$this->arraydata['data']=$arraynewdata;
               // $this->arraydata['date']=$arraydatecheck;
                $table='<table x:str BORDER="1" >';
                
                $table.='<tr>';
                $table.='<th>รายการ</th>';
                $table.='<th>ราคาขาย</th>';
                $table.='<th>ต้นทุนต่อเมนู</th>';
                $countdate=count($arraydatecheck['col'][0]);
                $table.='<th colspan="'.$countdate.'">จำนวนขาย</th>';
                $table.='</tr>';
                
                $table.='<tr>';
                $table.='<td>&nbsp</td>';
                $table.='<td>&nbsp</td>';
                $table.='<td>&nbsp</td>';
                if(count($arraydatecheck['col'][0]))
                {
                foreach($arraydatecheck['col'][0] as $valuedate)
                {
                $table.='<td>'.$valuedate.'</td>';
                }
                }
                $table.='</tr>';
                
                
                
                
                $table.='<tr>';
                $table.='<td>&nbsp</td>';
                $table.='<td>&nbsp</td>';
                $table.='<td>&nbsp</td>';
                if(count($arraydatecheck['col'][1]))
                {
                foreach($arraydatecheck['col'][1] as $valuedate)
                {
                $table.='<td>'.$valuedate.'</td>';
                }
                }
                $table.='</tr>';
                
                
                
               if(count($arraynewdata))
               {
               
               foreach($arraynewdata as $valuedatatag)
               {
               $table.='<tr>';
               $table.='<td>'.$valuedatatag['name'].'</td>';
               $table.='<td colspan="'.($countdate+2).'">&nbsp</td>';
               $table.='</tr>';
               if(count($valuedatatag['data']))
               {

               foreach($valuedatatag['data'] as $valuedataall)
               {
               $table.='<tr>';
               $table.='<td>'.$valuedataall['title'].'</td>';
               $table.='<td>'.$valuedataall['price'].'</td>';
               if($this->get['output'])
                {
                $table.='<td>'.$valuedataall['oprice'].'</td>';
                
                }else
                {
                $table.='<td><input type="text" id="pricecheck-'.$valuedataall['priceid'].'" value="'.$valuedataall['oprice'].'"  ><input type="button" value="Save" onclick="updateoriginalprice('.$valuedataall['priceid'].')" ></td>';
                
                }
               
               
               
               if(count($valuedataall['countorder']))
               {
               foreach($valuedataall['countorder'] as $valuecheckorder2)
               {
               
               
               $table.='<td>'.$valuecheckorder2.'</td>';
               
               
               }
               
               
               
               
               }
               
               
               $table.='</tr>';
               
               
               }
               
               $table.='</tr>';
               
               }
               
               
               
               
               
               
               
               }
               
               }
               
               

               
               
               
                if(count($arraydatecheck['col'][1]))
                {$krow=0;
                foreach($arraydatecheck['col'][1] as $valuedate)
                {
                
                $table.='<tr>';
               $table.='<td  colspan="'.($countdate+3).'">&nbsp</td>';
               $table.='</tr>';
               $table.='<tr>';
               $table.='<td  colspan="'.($countdate+3).'">&nbsp</td>';
               $table.='</tr>';
                
                
                $obj=$arraydatecheck['col'][3][$krow];
                
                $table.='<tr>';
                $table.='<td>'.$arraydatecheck['col'][0][$krow].' '.$valuedate.'</td>';
                $table.='<td>&nbsp</td>';
                $table.='<td>&nbsp</td>';
                $table.='<td  colspan="'.$countdate.'">&nbsp</td>';
                $table.='</tr>';
                
                
                
                $table.='<tr>';
                $table.='<td>รายได้</td>';
                $table.='<td>'.$obj['summary'].'</td>';
                $table.='<td>บาท</td>';
                $table.='<td  colspan="'.$countdate.'">&nbsp</td>';
                $table.='</tr>';
                
                
                
                $table.='<tr>';
                $table.='<td>ส่วนลด/Discount</td>';
                $table.='<td>'.$obj['discount'].'</td>';
                $table.='<td>บาท</td>';
                $table.='<td  colspan="'.$countdate.'">&nbsp</td>';
                $table.='</tr>';
                
                
                
                $table.='<tr>';
                $table.='<td>รายได้สุทธิ</td>';
                $table.='<td>'.$obj['total'].'</td>';
                $table.='<td>บาท</td>';
                $table.='<td  colspan="'.$countdate.'">&nbsp</td>';
                $table.='</tr>';
                
                
                $table.='<tr>';
                $table.='<td>ต้นทุนอาหาร</td>';
                $table.='<td>'.$obj['oprice'].'</td>';
                $table.='<td>บาท</td>';
                $table.='<td  colspan="'.$countdate.'">&nbsp</td>';
                $table.='</tr>';
                
                
                
                $table.='<tr>';
                $table.='<td>กำไรขั้นต้น</td>';
                $table.='<td>'.$obj['totalall'].'</td>';
                $table.='<td>บาท</td>';
                $table.='<td  colspan="'.$countdate.'">&nbsp</td>';
                $table.='</tr>';
                
                $krow++;
                
                }
                }
               
               
               
               
                $table.='</table>';
                
                

              //  $this->arraydata['data']=$arraynewdata;
                $this->arraydata['table']=$table;
                $this->arraydata['date']=$arraydatecheck;
                
                
                if($this->get['output'])
                {
                header("Content-Type: application/vnd.ms-excel");
                header('Content-Disposition: attachment; filename="tb_data_'.time().'.xls"');
                echo '   <html xmlns:o="urn:schemas-microsoft-com:office:office"

xmlns:x="urn:schemas-microsoft-com:office:excel"

xmlns="http://www.w3.org/TR/REC-html40">


<HTML>

<HEAD>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

</HEAD><BODY>';

                echo $this->arraydata['table'];
                
                echo '</BODY>

  </HTML>';
                
                }
                
                
                
                               //echo $table;
                
            
            }
            
            function testfacebook()
            {
    //        ini_set('display_errors',1);
//ini_set('display_startup_errors',1);
//error_reporting(-1);
                       
                      // use Facebook\FacebookCanvasLoginHelper;
                      // $this->helper = new FacebookCanvasLoginHelper(facebookappid, facebooksecret);
                       FacebookSession::setDefaultApplication(facebookappid,facebooksecret);

                      
                       $helper = new FacebookRedirectLoginHelper(baseinfo.'/ajax/testfacebook2?noredirect=1&nojson=1');
                       
           
                       
                       
                                       try {
  $session = $helper->getSessionFromRedirect();
} catch( FacebookRequestException $ex ) {
  // When Facebook returns an error
} catch( Exception $ex ) {
  // When validation fails or other local issues
}
                       
                      if ( isset( $session ) ) {
                      
                        $loginUrl = $helper->getLogoutUrl(); 
                      }else
                      { 
                      
                           
                        $params=array(
            'scope' => 'email,user_likes,user_photos,publish_stream,user_about_me,user_videos,status_update,user_birthday,user_location,user_work_history');
                       $loginUrl = $helper->getLoginUrl($params);   
                      }   
                       

            
            
            }
            
            function  testfacebook2()
            {

                        FacebookSession::setDefaultApplication(facebookappid,facebooksecret);  
                        $helper = new FacebookRedirectLoginHelper(baseinfo.'/ajax/testfacebook2?noredirect=1&nojson=1');
                        
                        try {
  $session = $helper->getSessionFromRedirect();
} catch( FacebookRequestException $ex ) {
  // When Facebook returns an error
} catch( Exception $ex ) {
  // When validation fails or other local issues
}
       
       if ( isset( $session ) ) {
                      
                        $request = new FacebookRequest( $session, 'GET', '/me' );
  $response = $request->execute();
  // get response
  $graphObject = $response->getGraphObject();
  
  
  
  
  echo "<pre>";
  print_r($graphObject);
  echo "</pre>;";
                      }
 
                        
                        
            
            }
            
            function setcolordata()
            {
            
         
                $userdata=$this->getuserbyoauth($this->userdata['oauth']); 
                if($this->post['productid']&&$this->post['color']&&$userdata['userid'])
                 {
                 
                        $sql='SELECT
tb_product.productid,
tb_plugins_infostant.contactid
FROM
tb_product
INNER JOIN tb_plugins_infostant ON tb_product.productid = tb_plugins_infostant.productid
where       tb_product.productid='.$this->post['productid'].' and tb_product.createby='.$userdata['userid'].'
';

                    $arraydata=$this->db->db_set_1recordrow($sql);
                    
                    if($arraydata['contactid'])
                    {
                           $arrayset=array();
                           $arrayset['color']=$this->post['color'];
                           $this->db->db_set($arrayset,'tb_plugins_infostant',' tb_plugins_infostant.contactid='.$arraydata['contactid']);
                    
                    }
                 
                 
                 
                 
                 }
            
            
            
            }
            
            function updateoriginalprice()
            {
            if($this->post['opriceid']&&$this->post['oprice'])
            {
            
            
            $arraydata['oprice']=$this->post['oprice'];
            $this->db->db_set($arraydata,'tb_plugins_price',' priceid='.$this->post['opriceid']);
            
            
            }
            
            
            
            }
           

           
           function testcrontab()
           {
            require_once (pluginpath.'/php-crontab-manager-master/crontab.php');
           // use 'php\manager\crontab\CrontabManager';

$crontab= new Crontab();

//$crontab->on('* * * * *');
//$crontab->onMinute('5')->doJob("/usr/bin/php ".rootpath.'/crontab/job1.php');
//$crontab->activate();
echo $crontab->listJobs();
           
            //$crontab = new CrontabManager();
//            $job = $crontab->newJob();
//            $job->on('* * * * *');
//            $job->onMinute('20-30')->doJob("echo foo");
//            $crontab->add($job);
//            $job->onMinute('35-40')->doJob("echo bar");
//            $crontab->add($job);
//            $crontab->save();
           
           }
           
           function phpversioncheck()
           {
           
           echo phpversion();
           
           }
           
           function confirmuser()
           {
           if($this->get['oauth'])
           {
           $oauth=$this->get['oauth'];
           
           $arrayuser=$this->getuserbyoauth($oauth);
           
           if($arrayuser['userid']&&$arrayuser['status']==0)
           {
           if(defined('privatedomain')&&privatedomain==1)
            {
            
            }else
            {
           $userArray['status']=1;
            }
            
           $userArray['oauth']=$oauth;

           $this->saveregister($userArray);
           $this->post['oauth']= $this->get['oauth'];
           $this->login();
           
           
           

           }
           else
           {
           $this->arraydata['error'][]=10;
           
           }
           
           
           }else
           {
           $this->arraydata['error'][]=11;  
           
           }
           
           header('Refresh: 1; URL='.baseinfo);
           
           
           }
           
           function __destruct() 
           {
             
              
              
              if(count($this->db->db_get_error()))
              {
                 
                //$sqlerror=join("|",$this->db->db_get_error());
                $this->arraydata['error'][]=1;//$this->db->db_get_error();
                $this->arraydata['error']['response']=1;
                
                
              }else if($this->arraydata['error']=="")
              {
                $this->arraydata['error']['response']=0;
              }else
              {
              
                 $this->arraydata['error']['response']=1;
              }
              
              if($this->arraydata['error']['response']==1)
              {
               if(count($this->arraydata['error'])&&is_array($this->arraydata['error']))
               {
               $error=array();

               foreach($this->arraydata['error'] as $key=> $valueerror)
               {
               

               if(is_numeric($key))
               {
                $error[]=$this->geterror($valueerror);
               
               

               
               }
               
               
               
               
               
               }
               
               
               }
              $this->arraydata['error']=array();
              $this->arraydata['error']['response']=count($error);
              $this->arraydata['error']['error']=$error;
              
              
              }
              
              if(!$this->get['nojson'])
              {
                            
                          //  $length = ob_get_length();
           
             
             //header("Content-Length: $length"); 
              echo   json_encode($this->arraydata);
              
             //ob_end_flush(); 
             
             //header('Content-Length: '.ob_get_length());
             header('Content-type: application/json');
             //ob_end_flush();
             
              //$length = ob_get_length();
//header("Content-Length: $length"); 
              }  
              
               $this->db->closedb(); 
            }
           function checkstatusserver()
           {
           echo "<pre>";
           print_r($_SERVER);
           echo "</pre>;";
           }
           function getmyuser()
           {
            
            if($this->userdata['oauth'])
            {
             $select="";
             if(count($this->post['select']))
             {
             $select=join(",",$this->post['select']);
             }
             
             $where['oauth']=$this->userdata['oauth'];
             
             $this->arraydata['data']=$this->getdatarow("tb_user",$select,$where,1);
             
             }else
             {
             $this->arraydata['error'][]=12;
             }
            
            }
            
            function getdistrict()
            {
             if($this->get['proid'])
             {
             $proid=$this->get['proid'];
             if(isset($this->get['swap']))
             {
             $swap=$this->get['swap'];
             } else
             {
            $swap=2; 
             
             }
             $this->arraydata['data']=parent::getdistrict($proid,'disname',$swap);
             
             }else
             {
            
              $this->arraydata['error'][]=13; 
             
             }
            
            
            }
            
            
            
             function getprovince()
            {
             $swap=1;
              if($this->get['noswap'])
              {
            $swap=0;  
              }
             $this->arraydata['data']=parent::getprovince('proname',$swap);
             
            
            
            
            }
            
            function getcountry()
            {
            $swap=1;
              if($this->get['noswap'])
              {
            $swap=0;  
              }
            $this->arraydata['data']=parent::getcountry('name',$swap);
            }
            
            function gettumbon()
            {
             if($this->get['disid'])
             {
             $disid=$this->get['disid'];
              if(isset($this->get['swap']))
             {
             $swap=$this->get['swap'];
             } else
             {
            $swap=2; 
             
             }
             $this->arraydata['data']=parent::gettumbon($disid,'tumname',$swap);
             
             }else
             {
            
              $this->arraydata['error'][]=14; 
             
             }
            
            
            }
            
            function testdata()
            {
            $string  = 'helloworld-123456'.'-database64';
$encoded = base64_encode($string);
//$decoded =  base64_decode($encoded);
echo $encoded ."\n";
//echo $decoded ."\n";
$compressed   =  gzdeflate($encoded);
//$uncompressed = gzinflate($compressed);

echo $compressed ."\n";
//echo $uncompressed;
            
            }
            function testdata2()
            {
            $text="123456";
            $encode=$this->encodetext($text);
                   // echo $encode."\n";
            
            // $decode=$this->decodetext($encode);
                  //  echo $decode."\n";
            
            
            }
            
            function checktestpost()
           {
            
            $testpost=$this->get['testpost'];
            $testpost;
            unset($this->get['testpost']);
            $this->post=$this->get;
            

            if (method_exists($this, $testpost))
                {
                eval("\$this->" . $testpost . "();");
                }
            else
                {
                //    echo "error";
                }
            
            
            }
            
            
            function cleantagdata()
            {
            $inputtag='NW';
            $sinputtag=array('KKN','NMA','UDN');
            
            $sql="SELECT
tb_tag.tagid
FROM
tb_tag
where tb_tag.`name` = '$inputtag'";
            $arraytag=$this->db->db_set_1recordrow($sql);
            
            if($arraytag['tagid'])
            {
            $tagid=$arraytag['tagid'];
            
            }else
            {
            
            $arraydata=array();
            $arraydata['name']=$inputtag;
            $arraydata['all']=0;
            $arraydata['system']=0;
            $arraydata['fid']=0;
            $arraydata['createby']=19;
            $this->db->db_set($arraydata,'tb_tag');
            $tagid=$this->db->db_get_last_number();
            
            
            
            }
            
            if(count($sinputtag))
            {
            foreach($sinputtag as $valuesearch)
            {
            
            $sql="SELECT
tb_relate_tag.productid,
tb_relate_tag.createby
FROM
tb_tag
INNER JOIN tb_relate_tag ON tb_relate_tag.tagid = tb_tag.tagid
where tb_tag.`name` = '".$valuesearch."' ";
            
            $arraytagcheck=$this->db->db_set_recordset($sql);
            
            if(count($arraytagcheck))
            {
            $krow=1;
            foreach($arraytagcheck as $valuechecktag)
            {
            
           
            $sql="SELECT
tb_relate_tag.rtagid
FROM
tb_relate_tag
where tb_relate_tag.`tagid` = ".$tagid." and tb_relate_tag.productid=".$valuechecktag['productid'];

$krow++;
            $arraycheck2=$this->db->db_set_1recordrow($sql);
            if($arraycheck2['rtagid'])
            {
            
            
            
            
            }else
            {

            //echo $valuechecktag['productid'];
//            exit;
            $arraydata=array();
            $arraydata['productid']=$valuechecktag['productid'];
            $arraydata['tagid']=$tagid;
            $arraydata['createby']=$valuechecktag['createby'];
            $arraydata['createdate']=date("Y-m-d H:i:s");
           $this->db->db_set($arraydata,'tb_relate_tag');
            
            
            }
            
    
            
            }
            }
            
            






            
            
            
            }
            }
            
            
            }
            
            function checktestpostdata()
           {
            
            if($this->post)
            {
            $this->arraydata['data']=$this->post;
            }else
            {
            
            $this->arraydata['data']=$this->get;
            }
            
            
            
            }
            
            function getinfodata()
            {
            
            echo "<pre>";
            print_r($_SERVER);
            echo "</pre>;";
            }
            
            function statdatamobile()
            {
            if($this->post['uuid'])
            {
            $arraydata['uuid']=$this->post['uuid'];
            $arraydata['ip']=$_SERVER['REMOTE_ADDR'];
            $arraydata['agent']=$_SERVER['HTTP_USER_AGENT'];
            $arraydata['createdate']=date("Y-m-d H:i:s");
            $this->db->db_set($arraydata,'tb_statdata');
            }
            
            }
            
            function statdatamobilelanding()
            {
            
            if($this->post['productid'])
            {
            $arraydata['productid']=$this->post['productid']; 
            $arraydata['uuid']=$this->post['uuid'];
            $arraydata['ip']=$_SERVER['REMOTE_ADDR'];
            $arraydata['agent']=$_SERVER['HTTP_USER_AGENT'];
            $arraydata['createdate']=date("Y-m-d H:i:s");
            $this->db->db_set($arraydata,'tb_statdata_landing');
            }
            
            
            }
            
            
             function statdataweb()
            {

            if($this->post['productid'])
            {
            $userdata=$this->getuserbyoauth($this->userdata['oauth']);
           if($userdata['userid'])
           {
            $arraydata['createby']=$userdata['userid'];
           }
           
           if($this->post['uuid'])
           {
            $arraydata['uuid']=$userdata['uuid'];
           }
           
           
           
            $arraydata['productid']=$this->post['productid'];
           
           
            $arraydata['ip']=$_SERVER['REMOTE_ADDR'];
            $arraydata['agent']=$_SERVER['HTTP_USER_AGENT'];
            $arraydata['createdate']=date("Y-m-d H:i:s");
            $this->db->db_set($arraydata,'tb_view');
            }
     
            
            }
            
             function statdatashareweb()
            {

            if($this->post['productid']&&isset($this->post['caseid']))
            {
            if($this->userdata['oauth'])
            {
            $userdata=$this->getuserbyoauth($this->userdata['oauth']);
           if($userdata['userid'])
           {
            $arraydata['createby']=$userdata['userid'];
            $sql='select shareid from tb_share_stat where productid='.$this->post['productid'].' and caseid='.$this->post['caseid'].' and createby='.$userdata['userid'];
            $arraycheck=$this->db->db_set_1recordrow($sql);
            if($arraycheck['shareid'])
            {
            
            }else
            {
            $this->savegamenictaionbygxcid($userdata['userid'],7);
            
            }
            
           }
            }
            $arraydata['caseid']=$this->post['caseid'];
           
            $arraydata['productid']=$this->post['productid'];
           
           
            $arraydata['ip']=$_SERVER['REMOTE_ADDR'];
            $arraydata['agent']=$_SERVER['HTTP_USER_AGENT'];
            $arraydata['createdate']=date("Y-m-d H:i:s");
            $this->db->db_set($arraydata,'tb_share_stat');
            }
     
            
            }
            
              
            
            
            function testcurl()
            {
            
            $urlWithoutProtocol="http://poll.pollcode.com/xoizc";
            $_POST['view']=' View ';
            $_POST['answer']=1;
            $urlWithoutProtocol2="http://hpc6.anamai.moph.go.th/hpc6/%E0%B8%84%E0%B8%93%E0%B8%B0%E0%B8%AF%E0%B8%A3%E0%B8%B2%E0%B8%8A%E0%B8%81%E0%B8%B2%E0%B8%A3%E0%B9%83%E0%B8%AA%E0%B8%AA%E0%B8%B0%E0%B8%AD%E0%B8%B2%E0%B8%94/1171-%E0%B8%9A%E0%B8%A3%E0%B8%B4%E0%B8%81%E0%B8%B2%E0%B8%A3%E0%B8%9D%E0%B8%B2%E0%B8%81%E0%B8%84%E0%B8%A3%E0%B8%A3%E0%B8%A0%E0%B9%8C%E0%B9%83%E0%B8%AB%E0%B8%A1%E0%B9%88-%E0%B8%A8%E0%B8%B9%E0%B8%99%E0%B8%A2%E0%B9%8C%E0%B8%AD%E0%B8%99%E0%B8%B2%E0%B8%A1%E0%B8%B1%E0%B8%A2%E0%B8%97%E0%B8%B5%E0%B9%88-6.html";
            
            
           // echo FetchContent($urlWithoutProtocol,'','C:\Documents and Settings\Administrator\Local Settings\Temporary Internet Files\cookies.txt',$urlWithoutProtocol2,$_POST,1);
          //  echo '<script>$("#answer1").trigger("click");</script>';
           

            
            
            }  
             
            function iupload()
            {
             $oauth=$this->userdata['oauth'];
             $arrayuser=$this->getuserbyoauth($oauth);

             if($arrayuser['userid']&&$_FILES["Filedata"]["tmp_name"])
             {
             
             if($this->checkallowuserspace($arrayuser['userid']))
             {
             
             $newfie=mktime().'-'.rand(0,100000);


             
             if(!is_dir(cacheimgpath.'/user/'.$arrayuser['userid']))
                     {
                      mkdir(cacheimgpath.'/user/'.$arrayuser['userid'],0777);
                      chmod(cacheimgpath.'/user/'.$arrayuser['userid'],0777);
                      }
                      
             $folder=cacheimgpath.'/user/'.$arrayuser['userid'];
             
              $typefile=".jpg";
              if($this->post['typefile'])
              {
              $typefile=".".$this->post['typefile'];
              }

             if(move_uploaded_file($_FILES["Filedata"]["tmp_name"], $folder.'/'.$newfie.$typefile)) 
                   {

                   
                   @chmod($folder.'/'.$newfie.$typefile,0777);
             
                   $this->rotateimage($folder.'/'.$newfie.$typefile);
                   
                   list($width, $height, $type, $attr) = getimagesize($folder.'/'.$newfie.$typefile);
                   $this->arraydata['filelink']=str_replace(rootpath,baseinfo,$folder).'/'.$newfie.$typefile;
                   $this->arraydata['filename']=$newfie.$typefile; 
                   
                   $this->arraydata['width']=$width;
                   $this->arraydata['height']=$height;
                   
                   
                   
                   $this->arraydata['imgmid']=$this->saveimage($width,$height,$folder.'/'.$newfie.$typefile,1,'','',$this->post['imgname'],1);
                   
                   
                   
          
                   
                   
                   }
             }else
             {
             $this->arraydata['error'][]=15;
             
             }
             
             }
             else
             {
             $this->arraydata['error'][]=16;
             
             }
             
             
             }
             
             function iuploaddata()
            {
             $oauth=$this->userdata['oauth'];
             $arrayuser=$this->getuserbyoauth($oauth);

             if($arrayuser['userid']&&$_FILES["img"]["tmp_name"])
             {
             
             if($this->checkallowuserspace($arrayuser['userid']))
             {
             
             $newfie=mktime().'-'.rand(0,100000);


             
             if(!is_dir(cacheimgpath.'/user/'.$arrayuser['userid']))
                     {
                      mkdir(cacheimgpath.'/user/'.$arrayuser['userid'],0777);
                      chmod(cacheimgpath.'/user/'.$arrayuser['userid'],0777);
                      }
                      
             $folder=cacheimgpath.'/user/'.$arrayuser['userid'];
             
              $typefile=".jpg";
              if($this->post['typefile'])
              {
              $typefile=".".$this->post['typefile'];
              }

             if(move_uploaded_file($_FILES["img"]["tmp_name"], $folder.'/'.$newfie.$typefile)) 
                   {

                   
                   @chmod($folder.'/'.$newfie.$typefile,0777);
             
                   $this->rotateimage($folder.'/'.$newfie.$typefile);
                   
                   list($width, $height, $type, $attr) = getimagesize($folder.'/'.$newfie.$typefile);
                   $this->arraydata['url']=str_replace(rootpath,baseinfo,$folder).'/'.$newfie.$typefile;
                   $this->arraydata['status']='success';
                   //$this->arraydata['filename']=$newfie.$typefile; 
                   
                   $this->arraydata['width']=$width;
                   $this->arraydata['height']=$height;
                   
                   
                   
                   $this->arraydata['imgmid']=$this->saveimage($width,$height,$folder.'/'.$newfie.$typefile,1,'','',$this->post['imgname'],1);
                   
                   
                   
          
                   
                   
                   }
             }else
             {
             $this->arraydata['error'][]=15;
             
             }
             
             }
             else
             {
             $this->arraydata['error'][]=16;
             
             }
             
             
             }
             
             function phpinfocheck()
             {
             
             phpinfo();
             }
            
             
            function iuploadfile()
            {
             $oauth=$this->userdata['oauth'];
             $arrayuser=$this->getuserbyoauth($oauth);           
             if($arrayuser['userid']&&$_FILES["Filedata"]["tmp_name"])
             {
             
             if($this->checkallowuserspace($arrayuser['userid']))
             {
             
             $newfie=mktime().'-'.rand(0,100000);
             
             
             if(!is_dir(cacheimgpath.'/user/'.$arrayuser['userid']))
                     {
                      mkdir(cacheimgpath.'/user/'.$arrayuser['userid'],0777);
                      chmod(cacheimgpath.'/user/'.$arrayuser['userid'],0777);
                      }
                      
             $folder=cacheimgpath.'/user/'.$arrayuser['userid'];
             
              $typefile=".jpg";
              if($this->post['typefile'])
              {
              $typefile=".".$this->post['typefile'];
              }
                      
             if(move_uploaded_file($_FILES["Filedata"]["tmp_name"], $folder.'/'.$newfie.$typefile)) 
                   {
                    @chmod($folder.'/'.$newfie.$typefile,0777);

                   $this->arraydata['filelink']=str_replace(rootpath,baseinfo,$folder).'/'.$newfie.$typefile;
                   $this->arraydata['fileid']=$this->savefile($newfie.$typefile,$this->post['imgname'],$folder.'/'.$newfie.$typefile,"",1);
                   $this->arraydata['filename']=$newfie.$typefile; 
                   
                   
                   }
             }else
             {
             $this->arraydata['error'][]=15;
             
             }
             
             }
             else
             {
             $this->arraydata['error'][]=16;
             
             }
             
             
             } 
            
            
            function testdatapush()
            {
            
            //   $fp = fopen('/var/log/php-fpm/www-error.log',"a");
//          $contents = stream_get_contents($fp);
//          $contents =$sql.";\n";
//              
//            $contents='';      
//          fwrite($fp,$contents);
//          fclose($fp); 
           
       //    chmod('/var/log/php-fpm',0777);  
//           chmod('/var/log/php-fpm/www-error.log',0777);    
//             exit;
         //   $data=file_get_contents('/var/log/php-fpm/www-error.log');
//            
//            $data=str_replace("\n","<br>",$data);
//            
//            
//            echo $data;
//            
//            exit;

                 require_once(rootpath.'/library/plugin/apns/ApnsPHP/Autoload.php'); // uri         
                 
                 
                 $push = new ApnsPHP_Push(
                 ApnsPHP_Abstract::ENVIRONMENT_PRODUCTION,
                 rootpath.'/assets/1368705720-10691.pem'
                 );

                 $push->setProviderCertificatePassphrase('123456');   
                // $push->setRootCertificationAuthority('/var/www/dpportal_80root_com/assets/entrust_root_certification_authority.pem');    
                 // Connect to the Apple Push Notification Service
$push->connect();

// Instantiate a new Message with a single recipient
$message = new ApnsPHP_Message('c91f4ef03a6683e145c76cb1e7e217a5f22e9ea7690ae0fd6416ee8a7c72456f');


// Set a custom identifier. To get back this identifier use the getCustomIdentifier() method
// over a ApnsPHP_Message object retrieved with the getErrors() message.
$message->setCustomIdentifier("Message-Badge-3");

// Set badge icon to "3"
$message->setBadge(3);

// Set a simple welcome text
$message->setText('Hello APNs-enabled device!');

// Play the default sound
$message->setSound();

// Set a custom property
$message->setCustomProperty('acme2', array('bang', 'whiz'));

// Set another custom property
$message->setCustomProperty('acme3', array('bing', 'bong'));

// Set the expiry value to 30 seconds
$message->setExpiry(30);

// Add the message to the message queue
$push->add($message);

// Send all messages in the message queue
$push->send();

// Disconnect from the Apple Push Notification Service
$push->disconnect();

// Examine the error message container
$aErrorQueue = $push->getErrors();
if (!empty($aErrorQueue)) {
    var_dump($aErrorQueue);
}   
                 
                 exit;
            
            
            }
            
            function saveactivitydatacenter()
            {
            
            $oauth=$this->userdata['oauth'];
             $arrayuser=$this->getuserbyoauth($oauth);           
             if($arrayuser['userid']&&($arrayuser['roleid']=='3'||$arrayuser['roleid']=='4'))
             {
            $title=$this->post['title'];
            $description=$this->post['description'];
            
            
            $startdate=$this->post['startdate'];
            $startdates=explode("/",$startdate);
            $startdate=$startdates[2].'-'.$startdates[1].'-'.$startdates[0];
            
            
            $enddate=$this->post['enddate'];
            $enddates=explode("/",$enddate);
            $enddate=$enddates[2].'-'.$enddates[1].'-'.$enddates[0];
            
            
            $totalamount=$this->post['totalamount'];
            $perday=$this->post['perday'];
            $imgmid=$this->post['imgmid'][0];
            $simgmid=$this->post['simgmid'][0];
            
            
            
            $arraydata=array();
            $arraydata['title']=$title;
            $arraydata['description']=$description;
            $arraydata['startdate']=$startdate;
            $arraydata['enddate']=$enddate;
            $arraydata['totalamount']=$totalamount;
            $arraydata['perday']=$perday;
            $arraydata['imgmid']=$imgmid;
            $arraydata['simgmid']=$simgmid;
            $arraydata['createby']=$arrayuser['userid'];
            
            $arraydata['updatedate']=date("Y-m-d H:i:s");
            
            
            
            if($this->post['rewardid'])
            {
            
            $this->db->db_set($arraydata,'tb_reward',' rewardid='.$this->post['rewardid']);
            
            }else
            {
            $arraydata['createdate']=date("Y-m-d H:i:s");
            $this->db->db_set($arraydata,'tb_reward');
            
            }
            
            
            
            
             }
            
            
            }
            
            function deleteactivitydatacenter()
            {
             $oauth=$this->userdata['oauth'];
             $arrayuser=$this->getuserbyoauth($oauth);           
             if($arrayuser['userid']&&$this->post['rewardid']&&($arrayuser['roleid']=='3'||$arrayuser['roleid']=='4'))
             {
             $arraydata['delete']=1;
             $this->db->db_set($arraydata,'tb_reward',' rewardid='.$this->post['rewardid']);
             
             
             }
            
            
            }
            
            function getitemdatacenter()
            {
          $oauth=$this->userdata['oauth'];
             $arrayuser=$this->getuserbyoauth($oauth);           
             if($arrayuser['userid'])
             {   
            $sql="
SELECT *,(perday-countdata) as totalperday FROM (

SELECT
    tb_reward.rewardid,
    tb_reward.title,
    tb_reward.description,
    tb_reward.startdate,
    tb_reward.enddate,
    tb_reward.totalamount,
    tb_reward.perday,
    tb_reward.imgmid,
    tb_reward.simgmid,
    (
        SELECT
            count(*)
        FROM
            tb_reward_relate
        WHERE
            tb_reward_relate.createdate BETWEEN '".date("Y-m-d")." 00:00:00' and '".date("Y-m-d")." 23:59:59'
        AND tb_reward_relate.rewardid = tb_reward.rewardid
    ) AS countdata
FROM
    tb_reward
WHERE
    `delete` = 0
AND startdate <= '".date("Y-m-d")."'
AND enddate >= '".date("Y-m-d")."'

) tb_data
where (perday-countdata)>0
";

$arraynewset=array();
$arraydata=$this->db->db_set_recordset($sql);
$arraysetrandom=array();
if(count($arraydata))
{
foreach($arraydata as $valuedata)
{

$valuedata['simg']=$this->getimagebyimgmid($valuedata['simgmid']);
$valuedata['img']=$this->getimagebyimgmid($valuedata['imgmid']);
$arraynewset[$valuedata['rewardid']]=$valuedata;

for($i=0;$i<intval($valuedata['totalperday']);$i++)
{
$arraysetrandom[]=$valuedata['rewardid'];


}



}


}


$data=array_rand($arraysetrandom);


$rewarid=$arraysetrandom[$data];      
$arraysave=array();
$arraysave['userid']=$arrayuser['userid'];
$arraysave['rewardid']=$rewarid;
$arraysave['createdate']=date("Y-m-d H:i:s");
$this->db->db_set($arraysave,'tb_reward_relate');

$this->arraydata['data']=$arraynewset[$rewarid];

             }

            
            
            }
            
            
            
            function getactivitydatacenter()
            {
            
            
            $oauth=$this->userdata['oauth'];
             $arrayuser=$this->getuserbyoauth($oauth);           
             if($arrayuser['userid']&&$this->get['page']&&($arrayuser['roleid']=='3'||$arrayuser['roleid']=='4'))
             {
             
             
             $page=$this->get['page'];
            $page=(($page - 1) * 20);
            $limit="limit  $page,".'20';
             
            $sql='select * from tb_reward where tb_reward.delete=0 order by createdate desc '.$limit;
            $this->arraydata['data']=$this->db->db_set_recordset($sql);
            $k=0;
            if(count($this->arraydata['data']))
            {
            foreach($this->arraydata['data'] as $valuedata)
            {
            list($valuedata['startdate'])=explode(" ",$valuedata['startdate']);
            list($y,$m,$d)=explode("-",$valuedata['startdate']);
            $this->arraydata['data'][$k]['startdate']=$d.'/'.$m.'/'.$y;
            
            list($valuedata['enddate'])=explode(" ",$valuedata['enddate']);
            list($y,$m,$d)=explode("-",$valuedata['enddate']);
            $this->arraydata['data'][$k]['enddate']=$d.'/'.$m.'/'.$y;
            
            
            $this->arraydata['data'][$k]['img']=$this->getimagebyimgmid($valuedata['imgmid']);
            $this->arraydata['data'][$k]['simg']=$this->getimagebyimgmid($valuedata['simgmid']);
            
            $k++;
            
            
            
            }
            
            
            
            }
 
            $sql='select count(*) as countdata from tb_reward where tb_reward.delete=0';
            $data=$this->db->db_set_1recordrow($sql);
            $this->arraydata['count']=intval($data['countdata']);
 
 
             }
            
            
            
            }
            
            
            function getactivityrelatedatacenter()
            {
            
            
            $oauth=$this->userdata['oauth'];
             $arrayuser=$this->getuserbyoauth($oauth);           
             if($arrayuser['userid']&&$this->get['page']&&($arrayuser['roleid']=='3'||$arrayuser['roleid']=='4'))
             {
             
             
             $page=$this->get['page'];
            $page=(($page - 1) * 20);
            $limit="limit  $page,".'20';
             
            $sql='SELECT
tb_reward.title,
tb_reward_relate.createdate,
tb_user.imgmid,
tb_user.simgmid,
tb_user.username,
IF (tb_user.displayname = \'\', tb_user.username,tb_user.displayname) as displayname,
tb_reward_relate.userid
FROM
tb_reward_relate
INNER JOIN tb_reward ON tb_reward.rewardid = tb_reward_relate.rewardid
INNER JOIN tb_user ON tb_reward_relate.userid = tb_user.userid
order by createdate desc '.$limit;
            $this->arraydata['data']=$this->db->db_set_recordset($sql);
            $k=0;
            if(count($this->arraydata['data']))
            {
            foreach($this->arraydata['data'] as $valuedata)
            {
            
            
            list($valuedata['createdate'],$time)=explode(" ",$valuedata['createdate']);
            list($y,$m,$d)=explode("-",$valuedata['createdate']);
            $this->arraydata['data'][$k]['createdate']=$d.'/'.$m.'/'.$y.' '.$time;
            

            
            
            $this->arraydata['data'][$k]['img']=$this->getimagebyimgmid($valuedata['imgmid']);
            $this->arraydata['data'][$k]['simg']=$this->getimagebyimgmid($valuedata['simgmid']);
            
            $k++;
            
            
            
            }
            
            
            
            }
 
            $sql='select count(*) as countdata from tb_reward_relate';
            $data=$this->db->db_set_1recordrow($sql);
            $this->arraydata['count']=intval($data['countdata']);
 
 
             }
            
            
            
            }
            
            
            
            function saveactivityrelatedatacenter()
            {
            $oauth=$this->userdata['oauth'];
             $arrayuser=$this->getuserbyoauth($oauth);           
             if($arrayuser['userid']&&($arrayuser['roleid']=='3'||$arrayuser['roleid']=='4'))
             {
             
             
             
             }
            
            
            }
            
            
            
             
            function iuploadfilemp4()
            {
             $oauth=$this->userdata['oauth'];
             $arrayuser=$this->getuserbyoauth($oauth);           
             if($arrayuser['userid']&&$this->post['url'])
             {
             
             if($this->checkallowuserspace($arrayuser['userid']))
             {
             
             $newfie=mktime().'-'.rand(0,100000);
             
             
             if(!is_dir(cacheimgpath.'/user/'.$arrayuser['userid']))
                     {
                      mkdir(cacheimgpath.'/user/'.$arrayuser['userid'],0777);
                      chmod(cacheimgpath.'/user/'.$arrayuser['userid'],0777);
                      }
                      
             $folder=cacheimgpath.'/user/'.$arrayuser['userid'];
             
             
             $arrayuri=explode("/",$this->post['url']);
             $filename=$arrayuri[count($arrayuri)-1];
             list($filename1,$extfile)=explode(".",$filename);
             
              $typefile=".".$extfile;
             
              
                    
             if(file_put_contents($folder.'/'.$newfie.$typefile, file_get_contents($this->post['url'])))
             
                   {
                   
                    @chmod($folder.'/'.$newfie.$typefile,0777);

                   $this->arraydata['filelink']=str_replace(rootpath,baseinfo,$folder).'/'.$newfie.$typefile;
                   $this->arraydata['fileid']=$this->savefile($newfie.$typefile,$filename,$folder.'/'.$newfie.$typefile,"",1);
                   $this->arraydata['filename']=$newfie.$typefile; 
                   
                   
                   }
             }else
             {
             $this->arraydata['error'][]=15;
             
             }
             
             }
             else
             {
             $this->arraydata['error'][]=16;
             
             }
             
             
             } 
              
             
            function checkresizeupload()
            {
            $oauth=$this->userdata['oauth'];
            $arrayuser=$this->getuserbyoauth($oauth);  
            if($arrayuser['userid']&&$this->post['imgmid']&&$this->post['width'])
            {
            require_once pluginpath.'/resize/ThumbLib.inc.php';
            
            
            $arrayplugin['img']= $this->getimagebyimgmid($this->post['imgmid'],'','','',' ,basewidth,baseheight,imgname');
             $this->arraydata['setcheck']=$arrayplugin;
            $width=intval($this->post['width']);
            $height=intval($this->post['height']);
            
            $basewidth=intval($arrayplugin['img']['basewidth']);
            $baseheight=intval($arrayplugin['img']['baseheight']);
            
            
            if($width>$basewidth||$height>$baseheight||$height==0)
            {
            
          
               
             $path=rootpath.'/'.$arrayplugin['img']['path'];
             $newfie=mktime().'-'.rand(0,100000);
             list($list,$type)=explode(".",$arrayplugin['img']['path']);
             $folder=cacheimgpath.'/user/'.$arrayuser['userid'];
             $newpath=$folder.'/'.$newfie.'.'.$type;
             
            if(!is_file($newpath))
               {
               //echo $newpath;
               
               $this->cropimage($path,$width,$height,$newpath);
               $typefile='.'.$type;
            //   $this->arraydata['filelink']=str_replace(rootpath,baseinfo,$folder).'/'.$newfie.'.'.$type;
               //$this->arraydata['fileid']=$this->savefile($newfie.'.'.$type,$this->post['imgname'],$folder.'/'.$newfie.$typefile,"",1);
               //    $this->arraydata['filename']=$newfie.$typefile; 
                  list($width, $height, $type, $attr) = getimagesize($folder."/".$newfie.$typefile);

               
                   $this->arraydata['filelink']=str_replace(rootpath,baseinfo,$folder).'/'.$newfie.$typefile;
                   $this->arraydata['filename']=$newfie.$typefile;
                   $this->arraydata['width']=$width;
                   $this->arraydata['height']=$height;
                   
                   
                   $this->arraydata['imgmid']=$this->saveimage($width,$height,$folder.'/'.$newfie.$typefile,0,'',$this->post['imgmid'],$arrayplugin['img']['imgname'],1);
                   
               
               }
            
            
        
            
            
            
            }else
            {
            $this->arraydata['filelink']=$arrayplugin['img']['newpath'];
            $this->arraydata['filename']=$arrayplugin['img']['imgname'];
            $this->arraydata['width']=$arrayplugin['img']['width'];
            $this->arraydata['height']=$arrayplugin['img']['height'];
            $this->arraydata['imgmid']=$arrayplugin['img']['imgmid'];
            
           // $this->arraydata['data'];
            
            
            }
            
            
            
            
            }
            
            
            
            } 
                        
            function cropupload()
            {
            $oauth=$this->userdata['oauth'];
            $arrayuser=$this->getuserbyoauth($oauth);
            if($arrayuser['userid']&&$this->post['link']&&$this->post['scale']&&$this->post['imgmid'])
            {
            
               if($this->checkallowuserspace($arrayuser['userid']))
               {
            
                if(!is_dir(cacheimgpath.'/user/'.$arrayuser['userid']))
                     {
                      mkdir(cacheimgpath.'/user/'.$arrayuser['userid'],0777);
                      chmod(cacheimgpath.'/user/'.$arrayuser['userid'],0777);
                      }
                
                $targ_w = $targ_h = 150;
                $jpeg_quality = 90;
                 
                $src=str_replace(baseinfo,rootpath,$this->post['link']);
                
                
                require_once pluginpath.'/resize/ThumbLib.inc.php';
                
                $thumb = PhpThumbFactory::create($src);
                $thumb->setOptions(array('bgcolor'=> array(255, 255, 255)));
                
                $fullwidth=intval($this->post['scale']['w']);
                $fullheight=intval($this->post['scale']['h']);
                
                if(($this->post['originalwidth']/$this->post['originalheight'])==1)
                {
                $fullheight=$fullwidth;
                
                }
                
                
                
                $thumb->crop($this->post['scale']['x'],$this->post['scale']['y'],$fullwidth,$fullheight);
                
                
                $arraydata=explode(".",$this->post['link']);
                
                
                $format=$arraydata[count($arraydata)-1];
                $folder=cacheimgpath.'/user/'.$arrayuser['userid'];
                $arraydata2=explode("/",$this->post['link']);
                $newfile=$arraydata2[count($arraydata2)-1];
                $arraydata=explode(".",$newfile);
                $newfie=$arraydata[0].'-'.$fullwidth.'x'.$fullheight.'.'.$format;
                $fileName=$folder.'/'.$newfie;

                
                
                $thumb->save($fileName);
                
                
                
                
                //@chmod($newpath,0777);
                @chmod($fileName,0777);
                
                $this->cropimage($fileName,$this->post['originalwidth'],$this->post['originalheight'],$fileName);
                
                $this->arraydata['filelink']=str_replace(rootpath,baseinfo,$folder).'/'.$newfie;
                $this->arraydata['filename']=$newfie;
                $this->arraydata['width']=intval($this->post['scale']['w']);
                
                $this->arraydata['height']=intval($this->post['scale']['h']);
                
                
                $this->arraydata['imgmid']=$this->saveimage($this->post['originalwidth'],$this->post['originalheight'],$folder.'/'.$newfie.$typefile,0,'',$this->post['imgmid'],'',1);
                
                
                
                ;
               }
                else
                {
                $this->arraydata['error'][]=15;
                
                }
            
            
            }
            else
             {
             $this->arraydata['error'][]=16;
             
             }
            
            
            }
            
            function cropuploaddata()
            {
            $oauth=$this->userdata['oauth'];
            $arrayuser=$this->getuserbyoauth($oauth);
            if($arrayuser['userid']&&$this->post['imgUrl']&&$this->post['imgmid'])
            {

               if($this->checkallowuserspace($arrayuser['userid']))
               {
            
                if(!is_dir(cacheimgpath.'/user/'.$arrayuser['userid']))
                     {
                      mkdir(cacheimgpath.'/user/'.$arrayuser['userid'],0777);
                      chmod(cacheimgpath.'/user/'.$arrayuser['userid'],0777);
                      }
                      
                 $imgUrl = $_POST['imgUrl'];
                // original sizes
                $imgInitW = $_POST['imgInitW'];
                $imgInitH = $_POST['imgInitH'];
                // resized sizes
                $imgW = $_POST['imgW'];
                $imgH = $_POST['imgH'];
                // offsets
                $imgY1 = $_POST['imgY1'];
                $imgX1 = $_POST['imgX1'];
                // crop box
                $cropW = $_POST['cropW'];
                $cropH = $_POST['cropH'];
                // rotation angle
                $angle = $_POST['rotation'];

                $jpeg_quality = 100;
                
                
                
                
                

                $folder=cacheimgpath.'/user/'.$arrayuser['userid'];

                $newfie=rand(1,100000000).'-'.$imgInitW.'x'.$imgInitH;
                
                $output_filename = $folder.'/'.$newfie;

                // uncomment line below to save the cropped image in the same location as the original image.
                //$output_filename = dirname($imgUrl). "/croppedImg_".rand();
                 
                $what = getimagesize($imgUrl);

                switch(strtolower($what['mime']))
                {
                case 'image/png':
                    $img_r = imagecreatefrompng($imgUrl);
                    $source_image = imagecreatefrompng($imgUrl);
                    $type = '.png';
                    break;
                case 'image/jpeg':
                    $img_r = imagecreatefromjpeg($imgUrl);
                    $source_image = imagecreatefromjpeg($imgUrl);
                    error_log("jpg");
                    $type = '.jpeg';
                    break;
                case 'image/gif':
                    $img_r = imagecreatefromgif($imgUrl);
                    $source_image = imagecreatefromgif($imgUrl);
                    $type = '.gif';
                    break;
                default: die('image type not supported');
            }
                // resize the original image to size of editor
                $resizedImage = imagecreatetruecolor($imgW, $imgH);
                imagecopyresampled($resizedImage, $source_image, 0, 0, 0, 0, $imgW, $imgH, $imgInitW, $imgInitH);
                // rotate the rezized image
                $rotated_image = imagerotate($resizedImage, -$angle, 0);
                // find new width & height of rotated image
                $rotated_width = imagesx($rotated_image);
                $rotated_height = imagesy($rotated_image);
                // diff between rotated & original sizes
                $dx = $rotated_width - $imgW;
                $dy = $rotated_height - $imgH;
                // crop rotated image to fit into original rezized rectangle
                $cropped_rotated_image = imagecreatetruecolor($imgW, $imgH);
                imagecolortransparent($cropped_rotated_image, imagecolorallocate($cropped_rotated_image, 0, 0, 0));
                imagecopyresampled($cropped_rotated_image, $rotated_image, 0, 0, $dx / 2, $dy / 2, $imgW, $imgH, $imgW, $imgH);
                // crop image into selected area
                $final_image = imagecreatetruecolor($cropW, $cropH);
                imagecolortransparent($final_image, imagecolorallocate($final_image, 0, 0, 0));
                imagecopyresampled($final_image, $cropped_rotated_image, 0, 0, $imgX1, $imgY1, $cropW, $cropH, $cropW, $cropH);
                // finally output png image
                //imagepng($final_image, $output_filename.$type, $png_quality);
                imagejpeg($final_image, $output_filename.$type, $jpeg_quality);

   
                
                $this->arraydata['url']=str_replace(rootpath,baseinfo,$output_filename.$type);
                $this->arraydata['status']='success';
                $this->arraydata['imgmid']=$this->saveimage($imgInitW,$imgInitH,$output_filename.$type,0,'',$this->post['imgmid'],'',1);
                
                $sql='SELECT * FROM `tb_plugins_infostant_image` where productid='.$this->post['productid'].' and width='.$this->post['owidth'].''.' and height='.$this->post['oheight'].' 
                and tb_plugins_infostant_image.index='.$this->post['index'].' and tempid='.$this->post['tempid'];
                 $arrayset=array();
                $arrayinfo=$this->db->db_set_1recordrow($sql);
                $arrayset['imgmid']=$this->post['imgmid'];
                $arrayset['simgmid']=$this->arraydata['imgmid'];
                if($arrayinfo['infoimgid'])
                {
                
                
                $this->db->db_set($arrayset,'tb_plugins_infostant_image','infoimgid='.$arrayinfo['infoimgid']);
                
                }else
                {
                
                $arrayset['width']=$this->post['owidth'];
                $arrayset['height']=$this->post['oheight'];
                $arrayset['tempid']=$this->post['tempid'];
                $arrayset['index']=$this->post['index'];
                $arrayset['productid']=$this->post['productid'];
                
                
                $this->db->db_set($arrayset,'tb_plugins_infostant_image');
                
                }
                
                
                
               }
                else
                {
                $this->arraydata['error'][]=15;
                
                }
            
            
            }
            else
             {
             $this->arraydata['error'][]=16;
             
             }
            
            
            }
            
            function clouddata()
            {
            
            $oauth=$this->userdata['oauth'];
            $arrayuser=$this->getuserbyoauth($oauth);
            if($arrayuser['userid']&&$this->get['page'])
            {
            if($this->get['fecth']==1)
            {
            $this->arraydata['usergallery']=$this->getimagecloudbyuserid($arrayuser['userid'],$this->get['page']);
            }
            
            if($this->get['fecth']==2)
            {
            $this->arraydata['systemgallery']=$this->getimagecloudbysystem($this->get['page']);
            
            }
            
            
            }
            
            }
            function testnowdata()
            {
            $string="1,2,2,2,3,3,7,7,4,5,2,6,5,9,8";
            $arraydata=explode(",",$string);
            $arraydata=array_unique($arraydata,SORT_NUMERIC);
            
            
            
            }
            function checkimgmid()
            {
            $oauth=$this->userdata['oauth'];
            $arrayuser=$this->getuserbyoauth($oauth); 
            if($this->post['imgid']&&$arrayuser['userid'])
            {
            
                  
                  $arraydata=$this->getimagebyimgid($this->post['imgid'],6);
                  if($arraydata['createby']==$arrayuser['userid'])
                   {
                  
                  
                  $this->arraydata['width']=$arraydata['width'];
                  $this->arraydata['height']=$arraydata['height'];
                  $this->arraydata['filename']=$arraydata['name']; 
                  $this->arraydata['filelink']=baseinfo.'/'.$arraydata['path'];
                  $this->arraydata['imgmid']=$arraydata['imgmid'];
                  
                  
                  
                  }
                  else if($arraydata['system']==1)
                  {
                  

                  
                  $imgmid=$arraydata['imgmid'];
                  $imgid=$arraydata['imgid'];
                  
                  unset($arraydata['imgmid']);
                  unset($arraydata['imgid']);
                  
                  
                  list($namefileold,$extfile)=explode(".",$arraydata['name']) ;
                  $newfile=mktime().'-'.rand(1,1000000).'.'.$extfile; 
                  $arraydata['name']=$newfile;
                  $arraydata['system']=0;
                  
                  
                  if(!is_dir(cacheimgpath.'/user/'.$arrayuser['userid']))
                     {
                      mkdir(cacheimgpath.'/user/'.$arrayuser['userid'],0777);
                      chmod(cacheimgpath.'/user/'.$arrayuser['userid'],0777);
                      }
                   //$arraypath = explode("/",$arraydata['path']);
                  
                  if(copy(rootpath.'/'.$arraydata['path'],cacheimgpath.'/user/'.$arrayuser['userid'].'/'.$newfile))
                  {
                  
                     $arraydata['path']=cacheimgpath.'/user/'.$arrayuser['userid'].'/'.$newfile;
                     
                     $this->arraydata['imgmid']=$this->saveimage($arraydata['width'],$arraydata['height'],$arraydata['path'],1,"",'',$arraydata['imgname'],1);
                   //  $this->arraydata['path']=baseinfo.'/'.$arraydata['path'];
                     $this->arraydata['width']=$arraydata['width'];
                     $this->arraydata['height']=$arraydata['height'];
                     $this->arraydata['filename']=$newfile; 
                     $this->arraydata['filelink']= str_replace(rootpath,baseinfo,$arraydata['path']) ;
                     
                  }else
                  {
                  
                    $this->arraydata['error'][]=17;
                  }
                  
                  } 
                  
                  
                  
            
            }
            
            
            }
            
            function savelink()
            {
            $oauth=$this->userdata['oauth'];
            $arrayuser=$this->getuserbyoauth($oauth);
            if($arrayuser['userid']&&$this->post['url'])
            {
            if($this->checkallowuserspace($arrayuser['userid']))
            {
            
            $imgname=array_pop(explode("/",$this->post['url']));
            

            
            //array_pop(explode("/",$this->get['url']));
            
            list($namefileold,$extfile)=explode(".",$imgname) ;
                   $extfile=strtolower($extfile);
                  $newfile=mktime().'-'.rand(1,1000000).'.'.$extfile; 
                 // $arraydata['name']=$newfile;
                 // $arraydata['system']=0;
                  
                  
                  if(!is_dir(cacheimgpath.'/user/'.$arrayuser['userid']))
                     {
                      mkdir(cacheimgpath.'/user/'.$arrayuser['userid'],0777);
                      chmod(cacheimgpath.'/user/'.$arrayuser['userid'],0777);
                      }
                      //$this->arraydata['url']=$this->get['url'];
            //if(is_link($this->get['url'])  )
            if(filter_var($this->post['url'], FILTER_VALIDATE_URL) !== FALSE)
            {

               // $img = file_get_contents($this->post['url']);
//                file_put_contents(cacheimgpath.'/user/'.$arrayuser['userid'].'/'.$newfile, $img);
            
            
            if(@copy($this->post['url'],cacheimgpath.'/user/'.$arrayuser['userid'].'/'.$newfile))
                  {
                  
                     $arraydata['path']=cacheimgpath.'/user/'.$arrayuser['userid'].'/'.$newfile;
                     list($width, $height, $type, $attr) = getimagesize($arraydata['path']);
                     $this->arraydata['imgmid']=$this->saveimage($width,$height,$arraydata['path'],1,$this->post['url'],'',$imgname,1);
                     $this->arraydata['width']=$width;
                     $this->arraydata['height']=$height;
                     $this->arraydata['filename']=$newfile; 
                     $this->arraydata['filelink']=str_replace(rootpath,baseinfo,$arraydata['path']) ;
                  
                  
                  }
            else
                  {
                    
                    $this->arraydata['error'][]=17;
                  
                  }
            }else
            {
            
                  $this->arraydata['error'][]=18;
            }
            
            
            
            
            }
            else
            {
                $this->arraydata['error'][]=15;
                
            }
            
            
            }
            
            }
            function apiinstragram()
            {
            
            $query='https://api.instagram.com/v1/users/search?q=nongdark46&access_token=33522660.0c15eb3.09aa82ee62c5490ca8706bf60ea72c4d&count=1';
            $contents=file_get_contents($query);
            $arraynewdata=json_decode($contents);
//echo $arraynewdata->data[0]->id;
            $query='https://api.instagram.com/v1/users/'.$arraynewdata->data[0]->id.'/media/recent?access_token=33522660.0c15eb3.09aa82ee62c5490ca8706bf60ea72c4d&count=100';
            //$contents =file_get_contents('https://api.instagram.com/v1/users/'.$this->post['userid'].'/media/recent?access_token=33522660.0c15eb3.09aa82ee62c5490ca8706bf60ea72c4d&count=100');
//            $arraynewdata=json_decode($contents);

            $contents=file_get_contents($query);
            $arraynewdata=json_decode($contents);
            
//            echo "<pre>";
//            print_r($arraynewdata);
//            echo "</pre>;";
            
            $this->arraydata['data']=$arraynewdata;
            
;
            
            
            
            
         
         
            
            }
            function cronjobinstragram()
           {
           
           $sql="select * from tb_cronjob where tb_cronjob.status=1";
           $arraydata=$this->db->db_set_recordset($sql);
           if(count($arraydata))
           {
           foreach($arraydata as $valuedata)
           {
           $this->userdata['oauth']=$valuedata['oauth'];
           $offset="&count=20";
           if($valuedata['offset'])
           {
           $offset.='&max_id='.$valuedata['offset'];
           
           }
            
            if($valuedata['title'])
            {
            $this->post['title']=$valuedata['title'];
            
            }
            
            if($valuedata['fid'])
            {
            $this->post['fid']=$valuedata['fid'];
            
            }
            $this->post['infoid']=infoid;
            $this->post['tagsystem']=array();

           
            $query=$valuedata['url'].$offset;


            $contents=file_get_contents($query);
            $arraynewdata=json_decode($contents);
            $nocheck=0;
            $arraynewdata2=object_to_array($arraynewdata);
            if(count($arraynewdata2['data']))
            {
            foreach($arraynewdata2['data'] as $valuenewdata2)
            {
            $this->post['idref']=$valuenewdata2['id'];
            $sql="select productid from tb_product where idref='".$this->post['idref']."' and tb_product.delete=0";
            $arraycheck=$this->db->db_set_1recordrow($sql);
            if(!$arraycheck['productid'])
            {
            
            if($this->post['title']=="")
            {
            $this->post['title']=$valuenewdata2['user']['username'];
            }
            $this->post['url']=$valuenewdata2['images']['standard_resolution']['url'];
            $this->savelink();
            $this->post['imgmid']=$this->arraydata['imgmid'];
            $this->post['simgmid']=$this->arraydata['imgmid'];
            unset($this->post['url']);
            $strtag="#".$valuenewdata2['user']['username'];
            if(count($valuenewdata2['tags']))
            {
            foreach($valuenewdata2['tags'] as $valuetags)
            {
            if($valuetags)
            {
            $strtag.=" #".str_replace("#",'',$valuetags) ;
            }
            
            }
            
            }
            $this->post['taguser']=$strtag;
            $this->post['createdate']=date("d/m/Y H:i:s", intval($valuenewdata2["created_time"])) ;
            $this->post['updatedate']=date("Y-m-d H:i:s", intval($valuenewdata2["created_time"])) ;
            $plugins=array();
            if($valuenewdata2['videos'])
            {
             $embed=array_pop(explode("/",$valuenewdata2['videos']['standard_resolution']['url'])) ;
             $plugins[]=array('plugid'=>10,"url"=>$valuenewdata2['videos']['standard_resolution']['url'],"embed"=>$embed);
            
            }else
            {
            $detail=$valuenewdata2['caption']['text'];
            $plugins[]=array('plugid'=>14,"imgmid"=>$this->post['imgmid'],"simgmid"=>$this->post['imgmid'],"detail"=>$detail);
            if($detail)
            {
            $this->post['title']=$detail;
            }else if($valuedata['title'])
            {
            $this->post['title']=$valuedata['title'];
            
            }
            }
            if($valuenewdata2['location'])
            {
            $plugins[]=array('plugid'=>5,"lat"=>$valuenewdata2['location']['latitude'],"lng"=>$valuenewdata2['location']['longitude'],"detail"=>$detail);
            }
            
            $this->post['plugin']=$plugins;
            $this->post['status']=1;
            

            echo "<pre>";
            print_r($this->post);
            echo "</pre>;";
            $this->saveproduct();
            
            
            
            
            
            }
            else
            {
            $nocheck=1;
            break;
            }
            
            }
            }
            
            if($nocheck)
            {
            
            $arraydataset['offset']="";
            $arraydataset['status']=0;
            $arraydataset['updatedate']=date("Y-m-d H:i:s");
            $this->db->db_set($arraydataset,'tb_cronjob',' cronid='.$valuedata['cronid']);
            
            }else
            {
            
            $arraydataset=array();
            if($arraynewdata2['pagination']['next_max_id'])
            {
            
            $arraydataset['offset']=$arraynewdata2['pagination']['next_max_id'];
            
            }else
            {
            $arraydataset['offset']="";
            $arraydataset['status']=0;
            }
            
            $arraydataset['updatedate']=date("Y-m-d H:i:s");
            $this->db->db_set($arraydataset,'tb_cronjob',' cronid='.$valuedata['cronid']);
            
            }
           
           
           }
           
           
           
           }
           
           
           }
           function recronjobinstragram()
           {
           
           $sql="select * from tb_cronjob where tb_cronjob.status=0";
           $arraydata=$this->db->db_set_recordset($sql);
           if(count($arraydata))
           {
           foreach($arraydata as $valuedata)
           {
           
           $arraydataset=array();
           $arraydataset['status']=5;
           $arraydataset['updatedate']=date("Y-m-d H:i:s");
           $this->db->db_set($arraydataset,'tb_cronjob',' cronid='.$valuedata['cronid']);
           
           $this->userdata['oauth']=$valuedata['oauth'];
           $offset="&count=50";
           
            
            if($valuedata['title'])
            {
            $this->post['title']=$valuedata['title'];
            
            }
            
            if($valuedata['fid'])
            {
            $this->post['fid']=$valuedata['fid'];
            
            }
            $this->post['infoid']=infoid;
            $this->post['tagsystem']=array();

           
            $query=$valuedata['url'].$offset;


            $contents=file_get_contents($query);
            $arraynewdata=json_decode($contents);
            
            $arraynewdata2=object_to_array($arraynewdata);
            if(count($arraynewdata2['data']))
            {
            foreach($arraynewdata2['data'] as $valuenewdata2)
            {
            $this->post['idref']=$valuenewdata2['id'];
            $sql="select productid from tb_product where idref='".$this->post['idref']."' and tb_product.delete=0";
            $arraycheck=$this->db->db_set_1recordrow($sql);
            if($arraycheck['productid'])
              {
              
              break;
              }
            else  
            {
            
            if($this->post['title']=="")
            {
            $this->post['title']=$valuenewdata2['user']['username'];
            }
            $this->post['url']=$valuenewdata2['images']['standard_resolution']['url'];
            $this->savelink();
            $this->post['imgmid']=$this->arraydata['imgmid'];
            $this->post['simgmid']=$this->arraydata['imgmid'];
            unset($this->post['url']);
            $strtag="#".$valuenewdata2['user']['username'];
            if(count($valuenewdata2['tags']))
            {
            foreach($valuenewdata2['tags'] as $valuetags)
            {
            if($valuetags)
            {
            $strtag.=" #".str_replace("#",'',$valuetags) ;
            }
            
            
            }
            
            }
            
            $this->post['taguser']=$strtag;
            $this->post['createdate']=date("d/m/Y H:i:s", intval($valuenewdata2["created_time"])) ;
            $this->post['updatedate']=date("Y-m-d H:i:s", intval($valuenewdata2["created_time"])) ;
            $plugins=array();
            if($valuenewdata2['videos'])
            {
             $embed=array_pop(explode("/",$valuenewdata2['videos']['standard_resolution']['url'])) ;
             $plugins[]=array('plugid'=>10,"url"=>$valuenewdata2['videos']['standard_resolution']['url'],"embed"=>$embed);
            
            }else
            {
            $detail=$valuenewdata2['caption']['text'];
            $plugins[]=array('plugid'=>14,"imgmid"=>$this->post['imgmid'],"simgmid"=>$this->post['imgmid'],"detail"=>$detail);
            if($detail)
            {
            $this->post['title']=$detail;
            }else if($valuedata['title'])
            {
            $this->post['title']=$valuedata['title'];
            
            }
            }
            if($valuenewdata2['location'])
            {
            $plugins[]=array('plugid'=>5,"lat"=>$valuenewdata2['location']['latitude'],"lng"=>$valuenewdata2['location']['longitude'],"detail"=>$detail);
            }
            
            $this->post['plugin']=$plugins;
            $this->post['status']=1;
            if(trim($this->post['title'])==""||!$this->post['title'])
            {
            $valuenewdata2['user']['username'];
            }

            echo "<pre>";
            print_r($this->post);
            echo "</pre>;";
            $this->saveproduct();
            
            
            
            
            
            }
            
            
            }
            }

            
           $arraydataset=array();
           $arraydataset['status']=1;
           $arraydataset['updatedate']=date("Y-m-d H:i:s");
           $this->db->db_set($arraydataset,'tb_cronjob',' cronid='.$valuedata['cronid']);
           
           
           }
           
           
           
           }
           else
           {


           
           $arraydataset=array();
           $arraydataset['status']=0;
           $arraydataset['updatedate']=date("Y-m-d H:i:s");
           $this->db->db_set($arraydataset,'tb_cronjob',' cronid=5');
           
           echo "test";
           exit;
           
      
           
           }
           
           }
           
           function recronjobtaginstragram()
           {
           $sql="select * from tb_cronjob where status=3";
           $arraydata=$this->db->db_set_recordset($sql);
           if(count($arraydata))
           {
           foreach($arraydata as $valuedata)
           {
           $this->userdata['oauth']=$valuedata['oauth'];
           $offset="&count=50";
           
            
            if($valuedata['title'])
            {
            $this->post['title']=$valuedata['title'];
            
            }
            
            if($valuedata['fid'])
            {
            $this->post['fid']=$valuedata['fid'];
            
            }
            $this->post['infoid']=infoid;
            $this->post['tagsystem']=array();

           
            $query=$valuedata['url'].$offset;


            $contents=file_get_contents($query);
            $arraynewdata=json_decode($contents);
            
            $arraynewdata2=object_to_array($arraynewdata);
            if(count($arraynewdata2['data']))
            {
            foreach($arraynewdata2['data'] as $valuenewdata2)
            {
            $this->post['idref']=$valuenewdata2['id'];
            $sql="select productid from tb_product where idref='".$this->post['idref']."' and tb_product.delete=0";
            $arraycheck=$this->db->db_set_1recordrow($sql);
            if(!$arraycheck['productid'])
            {
            
            if($this->post['title']=="")
            {
            $this->post['title']=$valuenewdata2['user']['username'];
            }
            $this->post['url']=$valuenewdata2['images']['standard_resolution']['url'];
            $this->savelink();
            $this->post['imgmid']=$this->arraydata['imgmid'];
            $this->post['simgmid']=$this->arraydata['imgmid'];
            unset($this->post['url']);
            $strtag="#".$valuenewdata2['user']['username'];
            if(count($valuenewdata2['tags']))
            {
            foreach($valuenewdata2['tags'] as $valuetags)
            {
            if($valuetags)
            {
            $strtag.=" #".str_replace("#",'',$valuetags) ;
            }
            
            
            }
            
            }
            
            $this->post['taguser']=$strtag;
            $this->post['createdate']=date("d/m/Y H:i:s", intval($valuenewdata2["created_time"])) ; 
            $this->post['updatedate']=date("Y-m-d H:i:s", intval($valuenewdata2["created_time"])) ; 
            $plugins=array();
            if($valuenewdata2['videos'])
            {
             $embed=array_pop(explode("/",$valuenewdata2['videos']['standard_resolution']['url'])) ;
             $plugins[]=array('plugid'=>10,"url"=>$valuenewdata2['videos']['standard_resolution']['url'],"embed"=>$embed);
            
            }else
            {
            $detail=$valuenewdata2['caption']['text'];
            $plugins[]=array('plugid'=>14,"imgmid"=>$this->post['imgmid'],"simgmid"=>$this->post['imgmid'],"detail"=>$detail);
            if($detail)
            {
            $this->post['title']=$detail;
            }else if($valuedata['title'])
            {
            $this->post['title']=$valuedata['title'];
            
            }
            }
            if($valuenewdata2['location'])
            {
            $plugins[]=array('plugid'=>5,"lat"=>$valuenewdata2['location']['latitude'],"lng"=>$valuenewdata2['location']['longitude'],"detail"=>$detail);
            }
            
            $this->post['plugin']=$plugins;
            $this->post['status']=1;
            if(trim($this->post['title'])==""||!$this->post['title'])
            {
            $valuenewdata2['user']['username'];
            }

            echo "<pre>";
            print_r($this->post);
            echo "</pre>;";
            $this->saveproduct();
            
            
            
            
            
            }
            else
            {
            break;
            }
            
            }
            }

            
            
           
           
           }
           
           
           
           }
           
           
           }
           
            function saveproduct()
            {
           
            $oauth=$this->userdata['oauth'];
            $arrayuser=$this->getuserbyoauth($oauth);
            if($arrayuser['userid']&&$this->post)
            {
            

            
            $arraydata['title']=  $this->post['title'];
            
            getFilesFromDirMuti(includepath,$arraynow);
             if(array_search_r_like($this->post['title'], $arraynow)||array_search_r_like($this->post['title'], $this->info['configall']['feature']))
            {
            $this->post['title']=$this->post['title'].'1';
            }
            
            $arraydata['link']=str_replace(array("/"," ","?","&",";","#","'",'"','%'),"-",strip_tags(trim($this->post['title']))) ;
            
            
            
            $arraydata['description']=$this->post['description'];
            $arraydata['fid']=$this->post['fid'];
            $arraydata['infoid']=$this->post['infoid'];
            $arraydata['imgmid']=$this->post['imgmid'];
            $arraydata['simgmid']=$this->post['simgmid'];
            $arraydata['status']=$this->post['status'];
            $arraydata['updateby']=$arrayuser['userid'];
             if($this->post['updatedate'])
            {
            $arraydata['updatedate']=$this->post['updatedate'];
            }else
            {
            $arraydata['updatedate']=date("Y-m-d H:i:s");
            }
            
            if($this->post['idref'])
            {
            $arraydata['idref']=$this->post['idref'];
            }
            
            if($this->post['code'])
            {
            $arraydata['code']=$this->post['code'];
            }
            
            if(isset($this->post['ispoi']))
            {
            $arraydata['ispoi']=$this->post['ispoi'];
            }
            
            if($this->post['productid'])
            {
            
             if($this->post['createdate'])
            {
            list($date,$time)=explode(" ",$this->post['createdate']);
            list($d,$m,$y)=explode("/",$date);
            
            $arraydata['createdate']=$y.'-'.$m.'-'.$d.' '.$time.':00';
            
            
            }
            
            $this->db->db_set($arraydata,"tb_product",' productid="'.$this->post['productid'].'"');
            $productid=$this->post['productid'];
            }
            else
            {
            $set=1;
            $arraydata['createby']=$arrayuser['userid'];
            if($this->post['createdate'])
            {
            list($date,$time)=explode(" ",$this->post['createdate']);
            list($d,$m,$y)=explode("/",$date);
            
            $arraydata['createdate']=$y.'-'.$m.'-'.$d.' '.$time.':00';
            
            
            }else
            {
            $arraydata['createdate']=date("Y-m-d H:i:s");
            }
            
            $this->db->db_set($arraydata,"tb_product");
            $productid=$this->db->db_get_last_number();
            //$this->savescoredata($arrayuser['userid'],3);
            $this->savegamenictaionbygxcid($arrayuser['userid'],3);
            }
            
            if($set)
            {
            if(!is_dir(imgpath.'/'.$productid))
            {
            mkdir(imgpath.'/'.$productid,0777);
            chmod(imgpath.'/'.$productid,0777);
            }
            if(!is_dir(filepath.'/'.$productid))
            {
            mkdir(filepath.'/'.$productid,0777);
            chmod(filepath.'/'.$productid,0777);
            }
            
            
            }
            
            
            
            
            $arraydata2['imgmid']=$this->swicthpathimage($arraydata['imgmid'],$productid,1);
            
  //          if($arraydata2['imgmid']&&NameDmconnex=='Canonlife')
//            {
//            
//            $sql=' select other,tb_img.imgmid
//FROM
//tb_img
//where other!="" and other!="false" and other like "%Model%" and tb_img.imgmid='.$arraydata2['imgmid'];
//          $dataimg=$this->db->db_set_1recordrow($sql);
//          
//          
//          
//          $otherdata= json_decode($dataimg['other']);
//          $arraydata2['other']=object_to_array($otherdata);
//  
//            if($dataimg['imgmid'])
//            {                            
// $model='';
// if($arraydata2['other']['IFD0']['Model'])
// {
// $model=$arraydata2['other']['IFD0']['Model'];
// $this->savetagrelatedata($model,$productid);
// 
// }
// 
// 
//  $len='';
// if($arraydata2['other']['EXIF'])
// {
// if($arraydata2['other']['EXIF']['UndefinedTag:0xA434'])
// {
// $len=$arraydata2['other']['EXIF']['UndefinedTag:0xA434'];
// $this->savetagrelatedata($len,$productid);
// }
// 
// }
// 
// 
//   $focus='';
// if($arraydata2['other']['EXIF'])
// {
// if($arraydata2['other']['EXIF']['FocalLength'])
// {
// $focus=$arraydata2['other']['EXIF']['FocalLength'];
//$link=str_replace('/','-',$focus);
//$focus=eval($focus).'mm';
//list($d1,$d2)=explode("/",$focus);
//$focus=($d1/$d2).' mm';

//$this->savetagrelatedata($focus,$productid);
// 
// }
// 
// }
// 
// 
// 
// $shutter='';
// if($arraydata2['other']['EXIF'])
// {
// if($arraydata2['other']['EXIF']['ISOSpeedRatings'])
// {
// $shutter=$arraydata2['other']['EXIF']['ISOSpeedRatings'];
// $this->savetagrelatedata($shutter,$productid);
// }
// }
// 
// $aperture='';
//  if($arraydata2['other']['COMPUTED'])
// {
// if($arraydata2['other']['COMPUTED']['ApertureFNumber'])
// {
// $aperture=$arraydata2['other']['COMPUTED']['ApertureFNumber'];
// $this->savetagrelatedata($aperture,$productid);
// }
// }
// 
// 
//  $exposure='';
//  if($arraydata2['other']['EXIF'])
// {
// if($arraydata2['other']['EXIF']['ExposureTime'])
// {
// $exposure=$arraydata2['other']['EXIF']['ExposureTime'];
//  $this->savetagrelatedata($exposure,$productid);
// }
// }
// 
// }
//  
//  
//            
//            
//            }
            
            
            $arraydata2['simgmid']=$this->swicthpathimage($arraydata['simgmid'],$productid,1);
            $this->db->db_set($arraydata2,"tb_product",' productid="'.$productid.'"');
            $this->savetag($this->post['tagsystem'],$this->post['taguser'],$productid,$this->post['fid']);
            if(count($this->post['plugin']))
            {
            $this->saveplugins($this->post['plugin'],$productid);
            }
            
            
            
            $this->arraydata['data']['link']=$arraydata['link'];
            $this->arraydata['data']['productid']=$productid;
            
            }
            else
            {
            $this->arraydata['error'][]=4;
            
            }
            
            }
            
            
            function getproductsync()
            {
            


              $limit="";
              $innerjoin="";
              $groupby="";
              if($this->info['parameter'][1])
              {
              $where='tb_product.updatedate>="'.$this->info['parameter'][1].'" and tb_product.delete=0';
              
              
             
              
              

              $where2=array();
              if($this->info['configall']['feature'] )
              {
              foreach($this->info['configall']['feature'] as $valuefeature)
              {
              
              if($valuefeature['issync']==1)
              {
              $where2[]='tb_product.fid='.$valuefeature['fid'];
              
              }
              
              }
              
              }
            
            
             if(count($where2))
             {
             
               
             $where2=join(" or ",$where2);
             
             
            $where=' where '.$where.' and ('.$where2.')';
            
           // echo $where;
             
             
             $arraydata=$this->getproductbycondition($where,$limit,$orderby,$innerjoin,$groupby,$select,1);
              
             $this->arraydata['data']=$arraydata;
             }
            
             
             }
            
             
            
            
            }
            
            function getproductfollowsync()
            {
            
            
            
              $limit="";
              $innerjoin="";
              $groupby="";
              if($this->info['parameter'][1])
              {
              $where='tb_follow.updatedate>="'.$this->info['parameter'][1].'"';
              
              
             
              
              

              $where2=array();
              if($this->info['configall']['feature'] )
              {
              foreach($this->info['configall']['feature'] as $valuefeature)
              {
              
              if($valuefeature['issync']==1)
              {
              $where2[]='tb_product.fid='.$valuefeature['fid'];
              
              }
              
              }
              
              }
            
            
             if(count($where2))
             {
             
               
             $where2=join(" or ",$where2);
             
             
           // $where=' where '.$where.' and ('.$where2.')';
            
           // echo $where;
             
             $sql='  SELECT
                        tb_like.productid,
                        count(tb_like.productid) countlike
                        FROM
                        tb_like
                        INNER JOIN  (select productid from tb_product where tb_product.delete=0 and  ('.$where2.')  ) tb_product ON tb_like.productid = tb_product.productid 
                        where tb_like.`status`=2 and '.$where.'
                        GROUP BY productid
                        ';
                        
             $sql='SELECT 
tb_product.productid,
tb_follow.countfollow
from tb_product
inner join (
SELECT
tb_follow.userid,
count(tb_follow.userid) as countfollow
FROM
tb_follow
where tb_follow.`status`=2 and '.$where.'
GROUP BY tb_follow.userid )  tb_follow on tb_product.createby=tb_follow.userid
where tb_product.delete=0 and  ('.$where2.')
';
             
             $arraydata=$this->db->db_set_recordset($sql);
             
             
            // $arraydata=$this->getproductbycondition($where,$limit,$orderby,$innerjoin,$groupby,$select,1);
              
             $this->arraydata['data']=$arraydata;
             }
            
             
             }
            
            
            
            
            
            }
            
            function getproductlikesync()
            {
            


              $limit="";
              $innerjoin="";
              $groupby="";
              if($this->info['parameter'][1])
              {
              $where='tb_fav.updatedate>="'.$this->info['parameter'][1].'"';
              
              
             
              
              

              $where2=array();
              if($this->info['configall']['feature'] )
              {
              foreach($this->info['configall']['feature'] as $valuefeature)
              {
              
              if($valuefeature['issync']==1)
              {
              $where2[]='tb_product.fid='.$valuefeature['fid'];
              
              }
              
              }
              
              }
            
            
             if(count($where2))
             {
             
               
             $where2=join(" or ",$where2);
             
             
           // $where=' where '.$where.' and ('.$where2.')';
            
           // echo $where;
             
             $sql='  SELECT
                        tb_fav.productid,
                        count(tb_fav.productid) countlike
                        FROM
                        tb_fav
                        INNER JOIN  (select productid from tb_product where tb_product.delete=0 and  ('.$where2.')  ) tb_product ON tb_fav.productid = tb_product.productid 
                        where tb_fav.`status`=2 and '.$where.'
                        GROUP BY productid
                        ';
             
             $arraydata=$this->db->db_set_recordset($sql);
             
             
            // $arraydata=$this->getproductbycondition($where,$limit,$orderby,$innerjoin,$groupby,$select,1);
              
             $this->arraydata['data']=$arraydata;
             }
            
             
             }
            
             
            
            
            }
            
            
           
           
            
            
            
            function saveproductmobile()
            {
           
            $oauth=$this->userdata['oauth'];
            $arrayuser=$this->getuserbyoauth($oauth);
            if($arrayuser['userid']&&$this->post)
            {
            

            
            $arraydata['title']=  $this->post['title'];
            
            getFilesFromDirMuti(includepath,$arraynow);
             if(array_search_r_like($this->post['title'], $arraynow)||array_search_r_like($this->post['title'], $this->info['configall']['feature']))
            {
            $this->post['title']=$this->post['title'].'1';
            }
            
            $arraydata['link']=str_replace(array("/"," ","?","&",";"),"-",strip_tags(trim($this->post['title']))) ;
            
            $arraydata['description']=$this->post['description'];
            $arraydata['fid']=$this->post['fid'];
            $arraydata['infoid']=$this->post['infoid'];
            
            
            
            $arraydata['imgmid']= $this->savephotobase64($this->post['photomain']);
            $arraydata['simgmid']=$arraydata['imgmid'];
            
            
            $arraydata['status']=$this->post['status'];
            $arraydata['updateby']=$arrayuser['userid'];
            $arraydata['updatedate']=date("Y-m-d H:i:s");
            
            if($this->post['code'])
            {
            $arraydata['code']=$this->post['code'];
            }
            
            if(isset($this->post['ispoi']))
            {
            $arraydata['ispoi']=$this->post['ispoi'];
            }
            
            if($this->post['productid'])
            {
            
            $this->db->db_set($arraydata,"tb_product",' productid="'.$this->post['productid'].'"');
            $productid=$this->post['productid'];
            }
            else
            {
            
            $set=1;
            $arraydata['createby']=$arrayuser['userid'];
            $arraydata['createdate']=date("Y-m-d H:i:s");
            $this->db->db_set($arraydata,"tb_product");
            $productid=$this->db->db_get_last_number();
            //$this->savescoredata($arrayuser['userid'],3);
            $this->savegamenictaionbygxcid($arrayuser['userid'],3);
            }
            
            if($set)
            {
            if(!is_dir(imgpath.'/'.$productid))
            {
            mkdir(imgpath.'/'.$productid,0777);
            chmod(imgpath.'/'.$productid,0777);
            }
            if(!is_dir(filepath.'/'.$productid))
            {
            mkdir(filepath.'/'.$productid,0777);
            chmod(filepath.'/'.$productid,0777);
            }
            
            
            }
            
            
            $arraydata2['imgmid']=$this->swicthpathimage($arraydata['imgmid'],$productid,1);
            $arraydata2['simgmid']=$this->swicthpathimage($arraydata['simgmid'],$productid,1);
            $this->db->db_set($arraydata2,"tb_product",' productid="'.$productid.'"');
            $taguser="";
            if(count($this->post['taguser']))
            {
            foreach($this->post['taguser'] as $valueuser)
            {
            
            $taguser.=" #".$valueuser;
            
            }
            
            }
            
            $this->savetag($this->post['tagsystem'],$taguser,$productid,$this->post['fid']);
            
            $plugins[]=array('plugid'=>14,"imgmid"=>$arraydata2['imgmid'],"simgmid"=>$arraydata2['imgmid'],"detail"=>$detail);
            
            if($this->post['lat']&&$this->post['lng'])
            {
             $plugins[]=array('plugid'=>5,"lat"=>$this->post['lat'],"lng"=>$this->post['lng'],"detail"=>$detail);
            }
            
            if(count($plugins))
            {
            $this->saveplugins($plugins,$productid);
            }
            
            
            
            $this->arraydata['data']['link']=$arraydata['link'];
            $this->arraydata['data']['productid']=$productid;
            
            }
            else
            {
            $this->arraydata['error'][]=4;
            
            }
            
            }
            
            function getactivitylist()
            {
            $sql="select * from tb_activity_list";
            $arrayactive=$this->db->db_set_recordset($sql);
            $this->arraydata['data']=$arrayactive;
            
            
            
            
            }

            
            function deleteproduct()
            {
             $oauth=$this->userdata['oauth'];
             $arrayuser=$this->getuserbyoauth($oauth);
            if($arrayuser['userid']&&$this->post['productid'])
            {
            $sql="select tb_product.productid,tb_product.createby from tb_product where productid=".$this->post['productid'];
            $arraycheckproduct=$this->db->db_set_1recordrow($sql);
            if($arraycheckproduct['createby']==$arrayuser['userid']||$arrayuser['roleid']==3)
            {
            $arraydata=array();
            if($this->post['undelete'])
            {
            $arraydata['delete']=0;
            }else
            {
            $arraydata['delete']=1;
            
            }
            
            $arraydata['updateby']=$arrayuser['userid'];
            $arraydata['updatedate']=date("Y-m-d H:i:s");
            $this->db->db_set($arraydata,"tb_product",' productid="'.$this->post['productid'].'"');
            
            }else
            {
            $this->arraydata['error'][]=26;
            
            }
            
            
            }else
            {
            $this->arraydata['error'][]=4;
            }
            
            }
                      
            function getproduct_bk()
            {
            
             

              $where=array();
              $limit="";
              $innerjoin="";
              $groupby="";
             if($this->get['productid'])
             {
             
             
             
             $where[]=" productid=".$this->get['productid'];
             $limit="limit  0,1";
             
             }
             
             
             
             if($this->get['fid'])
             {
             
             $sql="SHOW TABLES LIKE 'tb_product_point'";
             $arraycheck=$this->db->db_set_1recordrow($sql);
                  if(count($arraycheck)==0)
                 {
                 $where[]=" fid=".$this->get['fid'];
                 
                 }else
                 {
                 
                 $where[]="( (fid=".$this->get['fid'].' or tb_product.productid IN (select productid from tb_product_point where fid='.$this->get['fid'].') ) )';
                 }
                 
             
             
             
             }
             
              if($this->get['nopoi']==1)
              {
              $where[]=" ispoi=1 ";
              }
              
             
             
            
             
             if($this->get['page'])
             {
             $page=$this->get['page'];
             $page=(($page - 1) * countpage);
             $limit="limit  $page,".countpage;
             
             }else
             {
             $page=0;
             $limit="limit  $page,".countpage;
             }
             if($this->get['deletezone'])
             {
             $where[]=" tb_product.delete=1 ";
             }else
             {
             $where[]=" tb_product.delete=0 ";
             }
             
             if($this->get['feed'])
             {
             $sql='SELECT
                        tb_product.productid
                        FROM
                        tb_follow
                        INNER JOIN tb_product ON tb_follow.userid = tb_product.createby
                        where tb_follow.createby="'.$this->get['feed'].'" and tb_follow.`status`=2 and tb_product.delete=0 and tb_product.status=1
                        order by tb_product.createdate desc '.$limit;
             $arraydatalike=$this->db->db_set_recordset($sql);
             $strwhereproductid=0;
             if(count($arraydatalike))
             {
              $arraywhereproduct=array();
              foreach($arraydatalike as $valuedatalike)
              {
              $arraywhereproduct[]=$valuedatalike['productid'];
              
              }
              $strwhereproductid=join(",",$arraywhereproduct); 
             
             }
             
             $where[]=" tb_product.productid IN ( $strwhereproductid ) ";
             $limit='';
             
             }
            else if($this->get['fav'])
             {
             
             $sql="select productid from tb_like where tb_like.createby=".$this->get['fav']." and tb_like.status=2 order by createdate desc $limit";
             $arraydatalike=$this->db->db_set_recordset($sql);
             $strwhereproductid=0;
             if(count($arraydatalike))
             {
              $arraywhereproduct=array();
              foreach($arraydatalike as $valuedatalike)
              {
              $arraywhereproduct[]=$valuedatalike['productid'];
              
              }
              $strwhereproductid=join(",",$arraywhereproduct); 
             
             }
             
             $where[]=" tb_product.productid IN ( $strwhereproductid ) ";
             
             
             
             }
             else if($this->get['trip'])
             {
             
             $where3=array();
             if($this->get['proid'])
             {
             $where3[]=" proid=".$this->get['proid'];
             
             }
             
             if($this->get['duid'])
             {
             $sql2="select value from tb_duration where duid=".$this->get['duid'];
             $arrayduration=$this->db->db_set_1recordrow($sql2);
             
             $where3[]=" day ".$arrayduration['value'];
             
             }
             
             
              if($this->get['budid'])
             {
             $sql2="select value from tb_budget where budid=".$this->get['budid'];
             $arraybudget=$this->db->db_set_1recordrow($sql2);
             
             $where3[]=" ( price ".$arraybudget['value']." or saleprice  ".$arraybudget['value']." ) ";
             
             }
             
             
             $where2=array();
             if($this->get['tagnamesearch'])
             {
               
               $arrtagname=explode(" ",$this->get['tagnamesearch']);
             
             $krow=0;
             $rowtagname=array();
             foreach($arrtagname as $valuetagname)
             {
             if(trim($valuetagname))
             {
            // $rowtagname[$krow]="'".$valuetagname."'";
             $where2[]=" tb_tag.name like '%".$valuetagname."%'";
             $krow++;
             }
             
             
             }
             
             
             $innerjoin2.=" inner join tb_relate_tag ON tb_product.productid=tb_relate_tag.productid ";
             $innerjoin2.=" inner join tb_tag ON tb_tag.tagid=tb_relate_tag.tagid ";
             $groupby2.=" group by tb_product.productid ";
             
             
           //  $where2[]=" tb_tag.name IN (".join("','",$rowtagname).")";
             
             
           }
             
             
             if(count($where2))
             {
               $where2=' and ('.join(" or ",$where2).')';
             
             }else
             {
              $where2="";
             
             }
             
             
             if(count($where3))
             {
               $where3=' where '.join(" and ",$where3);
             
             }else
             {
              $where3="";
             
             }
             
             
             $sql="SELECT tb_plugins_newtrip.productid FROM `tb_plugins_newtrip` 
             
             INNER JOIN (
             select tb_product.productid from tb_product
             $innerjoin2
             where tb_product.`delete`=0 
             $where2
             $groupby2

             ) tb_product ON tb_plugins_newtrip.productid=tb_product.productid 
             
             $where3
             
             ";
             
             
             $limit='';
             $arraydatalike=$this->db->db_set_recordset($sql);
             $strwhereproductid=0;
             if(count($arraydatalike))
             {
              $arraywhereproduct=array();
              foreach($arraydatalike as $valuedatalike)
              {
              $arraywhereproduct[]=$valuedatalike['productid'];
              
              }
              $strwhereproductid=join(",",$arraywhereproduct); 
             
             }
             
             $orderbyset="ORDER BY FIELD(productid,$strwhereproductid)";
             
             $where[]=" tb_product.productid IN ( $strwhereproductid ) ";
             
             
             
             }
             else
             {
             if($this->get['userid'])
             {
             $where[]=" tb_user.userid=".$this->get['userid'];
             if($this->get['userid']==$this->userdata['userid'])
             {
             
             
             
             }else
             {
             //$innerjoin.=" inner join tb_relate_tag ON tb_product.productid=tb_relate_tag.productid ";
             $userdata=$this->getuserbyuserid($this->get['userid'],' ,publish ');
             if($userdata['publish']==0)
             {
             if($this->userdata['oauth'])
             {
             
             
             $checkdata=$this->checkuserfollow($this->get['userid'],$this->userdata['oauth']);
             if($checkdata===true)
             {
             $where[]=" tb_product.status=1  ";
             
             }else
             {
             $where[]=" tb_user.publish=1  ";
             
             }
             
             }else
             {
             
             $where[]="   tb_user.publish=1 ";
             
             
             }
             }else
             {
             $where[]=" tb_product.status=1  ";
             
             }
             
             
             }
             
             }else
             {
             $where[]=" tb_product.status=1  ";
             }
             }
              
             if($this->get['search'])
             {
             $search=str_replace('#','',$this->get['search']) ;
             $sql='SELECT * from (

SELECT
tb_plugins_contact.productid
FROM
tb_plugins_contact
INNER JOIN (select productid from tb_product where tb_product.`delete`=0 and tb_product.`status`=1 ) as tb_product ON tb_plugins_contact.productid = tb_product.productid
LEFT JOIN tb_user ON tb_plugins_contact.sameaddressprofile = tb_user.userid
LEFT JOIN tb_province ON tb_user.proid = tb_province.proid
LEFT JOIN tb_district ON tb_user.disid = tb_district.disid
LEFT JOIN tb_tumbon ON tb_user.tumid = tb_tumbon.tumid
LEFT JOIN tb_province as  tb_province2 ON tb_plugins_contact.proid = tb_province2.proid
LEFT JOIN tb_district as  tb_district2 ON tb_plugins_contact.disid = tb_district2.disid
LEFT JOIN tb_tumbon as  tb_tumbon2 ON tb_plugins_contact.tumid = tb_tumbon2.tumid
where tb_tumbon.tumname like "%'.$search.'%" or tb_district.disname like "%'.$search.'%" or tb_province.proname like "%'.$search.'%" or tb_tumbon2.tumname like "%'.$search.'%" or tb_district2.disname like "%'.$search.'%" or tb_province2.proname like "%'.$search.'%"

UNION ALL


SELECT
tb_product.productid
FROM
tb_relate_tag
INNER JOIN tb_tag ON tb_tag.tagid = tb_relate_tag.tagid
INNER JOIN tb_product ON tb_relate_tag.productid = tb_product.productid
where (tb_product.`delete`=0 and tb_product.`status`=1) and (tb_tag.`name` like "%'.$search.'%" or tb_product.title like "%'.$search.'%" or tb_product.description like "%'.$search.'%"  ) 
) tb_product GROUP BY productid  '.$limit;
             $arraydatalike=$this->db->db_set_recordset($sql);
             //echo $sql;
             $strwhereproductid=0;
             if(count($arraydatalike))
             {
              $arraywhereproduct=array();
              foreach($arraydatalike as $valuedatalike)
              {
              $arraywhereproduct[]=$valuedatalike['productid'];
              
              }
              $strwhereproductid=join(",",$arraywhereproduct); 
             
             }
             
             $where[]=" tb_product.productid IN ( $strwhereproductid ) ";
             $limit='';
             }
             
             if(count($this->get['tagid']))
             {
             
             $innerjoin.=" left join tb_relate_tag ON tb_product.productid=tb_relate_tag.productid ";
             $groupby.=" group by tb_product.productid ";
             
             if($this->get['tagid'][0])
             {
             $where[]=" tb_relate_tag.tagid IN (".join(",",$this->get['tagid']).")";
             }else
             {
             $where[]=" tb_relate_tag.tagid IN (0)";
             
             }
             
             
             
             
             }
             
            
             
             if(count($this->get['tagnamearray']))
             {
             
             
              $innerjoin.=" left join tb_relate_tag ON tb_product.productid=tb_relate_tag.productid ";
              $innerjoin.=" left join tb_tag ON tb_tag.tagid=tb_relate_tag.tagid ";
             $groupby.=" group by tb_product.productid ";
             
             if($this->get['tagnamearray'][0])
             {
             $where[]=" tb_tag.name IN ('".join("','",$this->get['tagnamearray'])."')";
             }else
             {
             $where[]=" tb_tag.name IN (0)";
             
             }
             
             
             
             
             
             }
             
            
             
             if($this->get['lat']&&$this->get['lng'])
             {
                    $lat=$this->get['lat'];
                    $lng=$this->get['lng'];
                    if($this->get['distance'])
                    {
                    $lamda=$this->get['distance']/111.16581;
                    
                    }else
                    {
                    
                    $lamda=10/111.16581;
                    }
                    
             $where2=array();       
             if(count($this->get['tagname']))
             {
             $krow=0;
             $rowtagname=array();
             foreach($this->get['tagname'] as $valuetagname)
             {
             if(trim($valuetagname))
             {
            // $rowtagname[$krow]="'".$valuetagname."'";
             $where2[]=" tb_tag.name='".$valuetagname."'";
             $krow++;
             }
             
             
             }
             
             
             $innerjoin2.=" inner join tb_relate_tag ON tb_product.productid=tb_relate_tag.productid ";
             $innerjoin2.=" inner join tb_tag ON tb_tag.tagid=tb_relate_tag.tagid ";
             $groupby2.=" group by tb_product.productid ";
             
             
           //  $where2[]=" tb_tag.name IN (".join("','",$rowtagname).")";
             
             
             }
             
             if(count($where2))
             {
               $where2=' and ('.join(" or ",$where2).')';
             
             }else
             {
              $where2="";
             
             }
             
                    
                    $sql="SELECT
tb_plugins_map.lat,
tb_plugins_map.lng,
tb_plugins_map.mapid,
 POWER((tb_plugins_map.lat-".$lat."),2)+POWER(COS(RADIANS((tb_plugins_map.lat+".$lat.")/2)) * (tb_plugins_map.lng-".$lng."),2) AS distance,
tb_plugins_map.productid
FROM
tb_plugins_map
INNER JOIN (

select tb_product.productid from tb_product
$innerjoin2
where tb_product.`delete`=0 
$where2
$groupby2

) tb_product ON tb_plugins_map.productid=tb_product.productid
where tb_plugins_map.lat between ".(-$lamda+$lat)." AND ".($lamda+$lat)." AND tb_plugins_map.lng between ".(-$lamda+$lng)." AND ".($lamda+$lng)."GROUP BY tb_plugins_map.productid order by distance asc ".$limit;
//echo $sql;
             $limit='';
             $arraydatalike=$this->db->db_set_recordset($sql);
             $strwhereproductid=0;
             if(count($arraydatalike))
             {
              $arraywhereproduct=array();
              foreach($arraydatalike as $valuedatalike)
              {
              $arraywhereproduct[]=$valuedatalike['productid'];
              
              }
              $strwhereproductid=join(",",$arraywhereproduct); 
             
             }
             
             $orderbyset="ORDER BY FIELD(productid,$strwhereproductid)";
             
             $where[]=" tb_product.productid IN ( $strwhereproductid ) ";
             
             
             }
             
             
             if(count($where))
             {
               $where=' where '.join(" and ",$where);
             
             }else
             {
              $where="";
             
             }

             $select="";
             if($this->get['orderby'])
             {
             
              if($this->get['orderby']==1)
             {
             $select.=" ,(select count(tb_fav.favid) as countfav from tb_fav where  tb_product.productid=tb_fav.productid   )  as countlike ";
             $orderby=' order by countlike desc  ';
          //   $groupby=' GROUP BY tb_fav.productid ';
         //    $innerjoin.=" LEFT join tb_fav ON tb_product.productid=tb_fav.productid  ";
             
             }else if($this->get['orderby']==3)
             {
             $orderby=' order by rand()';
             
             }
             
             else
             {
             $orderby=' order by '.$this->get['orderby'];
             }
             
             
             
             
             
             
             }else
             {
             
             if($this->get['lat']&&$this->get['lng'])
             {
             $orderby=$orderbyset;
             }else
             {
             $orderby=1;
             }
             
             }
             

             $nomemcache=0;
             if($this->get['nocache'])
             {
             $nomemcache=1;
             
             }
             
             
             $arraydata=$this->getproductbycondition($where,$limit,$orderby,$innerjoin,$groupby,$select,$nomemcache);
             
             
             
              
             $this->arraydata['data']=$arraydata;
             
             $sql=" select count(tb_product.productid) as countproduct  from tb_product 
            inner join tb_user ON tb_user.userid=tb_product.createby  
            $innerjoin
            $where 
            $groupby 
            ";
            $datarow=$this->db->db_set_1recordrow($sql);
             
             $this->arraydata['total']= intval($datarow['countproduct']);
             $this->arraydata['page']= ceil($this->arraydata['total']/countpage);
             $this->arraydata['next']="";
             $this->arraydata['back']="";
              if($this->get['page']>1)
             {
             $set2=1;
             $this->get['page']=$this->get['page']-1;
             $this->arraydata['back']=baseinfo.'/ajax/getproduct'.'?'.http_build_query($this->get);
             
             
             }
             
             
             
             if(count($this->arraydata['data'])==countpage)
             {
             if($set2==1)
             {
             $count=2;
             }else
             {
             $count=1;  
             }
             
             $this->get['page']=$this->get['page']+$count;
             
             
             $this->arraydata['next']=baseinfo.'/ajax/getproduct'.'?'.http_build_query($this->get);
             
             }
            
             
            
            
            }
            
           function savestatadmin()
           {

           if(count($this->post['data'])&&is_array($this->post['data']))
           {
            //$this->arraydata['error']=print_r($this->post['data'],1);
             foreach($this->post['data'] as $valuedata)
             {
             
             if($valuedata['actid']&&$valuedata['date']&&$valuedata['uuid'])
             {
             $arraydata=array();
             
             if(is_numeric($valuedata['date']))
             {
             
             $valuedata['date']=date("Y-m-d H:i:s",$valuedata['date']);
             
             }
              $arraydata=$valuedata;
              $arraydata['createdate']= date("Y-m-d H:i:s");
              $arraydata['agent']=$_SERVER['HTTP_USER_AGENT'];
              $this->db->db_set($arraydata,"tb_stat_all"); 
             
             }
             else
             {
             
            $this->arraydata['error'].="ส่งข้อมูลไม่ครบแถว  => actid=>".$valuedata['actid']."shelfid=>".$valuedata['shelfid']."uuid=>".$valuedata['uuid']." \n";
             
             }
             
             
             
             
             }
           
           
           
           }
           else
           {
           $this->arraydata['error']="ส่งข้อมูลไม่ครบ";
           
           }
           
           
           }
           
            function checkstatus()
            {
            $this->arraydata['data']="1";
            
            }
            function checkisrinsbox()
            {
            $this->arraydata['data']="0";
            
            }
            
            function gettestinfo()
            {
            
               $everything=1;
               $arrayallow=array();
               
               if($this->userdata['roleid'])
               {
               
               }
               if($roleid)
               {
               
               }
               foreach($this->info['configall']['feature'] as $valuefeature)
                      {
                         
                       if(isset($valuefeature['showread']))
                         {
                         $everything=0;

                         if(is_array($valuefeature['showread']))
                         {
                         if(array_search('0',$valuefeature['showread'])!==false)
                         {
                         $arrayallow[]=$valuefeature['fid'];
                        // $boolean=true;
                         }
                         else  if(array_search($roleid,$valuefeature['showread'])!==false)
                         {
                         $arrayallow[]=$valuefeature['fid'];
                        // $boolean=true;
                         
                         }
                         else
                         {
                     //    $boolean=false;
                         
                         }
                         }
                         else
                         {
                       //  $boolean=false;
                         
                         }
                         
                         }else
                         {
                         
                         
                         
                         }
                      
                      
                       
                       if($valuefeature['show']&&$boolean)
                       {
           
                            if($valuefeature['fid'])
                            {
                            
                            
                            
                            
                            }
                   
                       
                       }
                      }
             
            
            
            $this->arraydata['data']=$this->info['configall']['feature'];
            
            
            }
            
           
           function checkpostpurchase()
           {
           $oauth=$this->userdata['oauth'];
             $arrayuser=$this->getuserbyoauth($oauth);
             $check=false;
           if($this->post['productid']&&$arrayuser['userid'])
           {
           
           $sql='select credithid from tb_pay_credit_history where productid='.$this->post['productid'].' and userid='.$arrayuser['userid'];
           
           $arraydata=$this->db->db_set_1recordrow($sql);
           
           if($arraydata['credithid'])
           {
           
           $check=true;
           
           $this->arraydata['plugins']=$this->getplugins($this->post['productid']);
           
           
           }else
           {
           $check=false;
           
           }
           
           
           }
           
           $this->arraydata['check']=$check;
           
           
           }
           
           function savecoindata()
           {
            if($this->userdata['oauth'])
           {
           $oauth=$this->userdata['oauth'];
           $arrayuser=$this->getuserbyoauth($oauth);
           if($this->post['productid']&&$arrayuser['userid'])
           {
           $mycredit=$this->getcreditdata($arrayuser['userid']);
           
           $sql='select credit from tb_product where productid='.$this->post['productid'];
           $checkproduct=$this->db->db_set_1recordrow($sql);
           if($checkproduct['credit'])
           {
           $credit=intval($checkproduct['credit']);
           }else
           {
           $credit=0;
           
           }
           
           if(($mycredit>=$credit)&&$credit!=0&&$mycredit!=0)
           {
           $totalcredit=$mycredit-$credit;
           $arraydata=array();
           $arraydata['credit']=$totalcredit;
           $arraydata['updatedate']=date("Y-m-d H:i:s");
           $this->db->db_set($arraydata,'tb_pay_credit',' userid='.$arrayuser['userid']);
           
           
           
           
           $arraydata=array();
           $arraydata['credit']=$credit;
           $arraydata['productid']=$this->post['productid'];
           $arraydata['userid']=$arrayuser['userid'];
           $arraydata['createby']=$arrayuser['userid'];
           $arraydata['createdate']=date("Y-m-d H:i:s");
           $this->db->db_set($arraydata,'tb_pay_credit_history');
           
           $this->arraydata['data']=array();
           
           }else
           {
           $this->arraydata['error'][]=44;
           
           }
           
           
           
           
           }else
           {
           
           $this->arraydata['error'][]=5;
           
           }
           
           }
           
           
           
           }
            
            function getproduct()
            {
                if(NameDmconnex=='Thailand one click'&&$this->get['fid']=='1000')
                {
               require_once(pluginpath.'/t1c/T1C_ServiceService.php'); // uri
               $s=new T1C_ServiceService();
               
$lat=NULL;
$lng=NULL;
$orderBy=NULL;
$distance=NULL;
$search=NULL;
 $arraydata=json_decode($s->getPoi(intval($this->get['page']),NULL,NULL,NULL,NULL,$search,$orderBy,$lat,$lng,$distance,NULL,NULL,NULL,NULL,NULL,NULL));
              //json_decode($s->getPoi($this->get['page'],null,null,null,null,null,'Butterfly'));
               $arraydata=object_to_array($arraydata);
               if(count($arraydata['data']))
               {
               $k=0;
               $arraydata2['newpath']=baseinfo.'/img/dfthmbcell.jpg';
               $arraydata2['width']= 600;
               $arraydata2['height']=600;
               foreach($arraydata['data'] as $valuedata2)
               {
               
               $arraydata['data'][$k]['productid']=''.rand(999999,10000000);
               $arraydata['data'][$k]['countlike']=0;
               $arraydata['data'][$k]['checklike']=false;
               $arraydata['data'][$k]['countview']=0;
               $arraydata['data'][$k]['checkbookmark']=false;
               $arraydata['data'][$k]['countbookmark']=0;
               $arraydata['data'][$k]['countcomment']=0;
               $arraydata['data'][$k]['countfollow']=0;
               $arraydata['data'][$k]['checkfollow']=false;
               
               
               
               $arraydata['data'][$k]['userssimg']=$arraydata2;
               $arraydata['data'][$k]['usersimg']=$arraydata2;
               
               

               
               
               $k++;
               
               }
               }

               
               $this->arraydata=object_to_array($arraydata);
               //require_once('');
               exit; 
                }
              $where=array();
              $limit="";
              $innerjoin="";
              $groupby="";
              $nodatacheckdate=1;
             if($this->get['productid'])
             {
             
             
             
             $where[]=" productid=".$this->get['productid'];
             $limit="limit  0,1";
             
             }
             
           
             if($this->get['fid'])
             {
             
             $sql="SHOW TABLES LIKE 'tb_product_point'";
             $arraycheck=$this->db->db_set_1recordrow($sql);
                  if(count($arraycheck)==0)
                 {
                 $where[]=" fid=".$this->get['fid'];
                 
                 }else
                 {
                 
                 $where[]="( (fid=".$this->get['fid'].' or tb_product.productid IN (select productid from tb_product_point where fid='.$this->get['fid'].') ) )';
                 }
                 
             
             
             
             }
             
              if($this->get['nopoi']==1)
              {
              $where[]=" ispoi=1 ";
              }
              
             
             
             
             
             if($this->get['page'])
             {
             $page=$this->get['page'];
             $page=(($page - 1) * countpage);
             $limit="limit  $page,".countpage;
             
             }else
             {
             $page=0;
             $limit="limit  $page,".countpage;
             }
             if($this->get['deletezone'])
             {
             $where[]=" tb_product.delete=1 ";
             }else
             {
             $where[]=" tb_product.delete=0 ";
             }
             
             if($this->get['feed'])
             {
             $sql='SELECT
                        tb_product.productid
                        FROM
                        tb_follow
                        INNER JOIN tb_product ON tb_follow.userid = tb_product.createby
                        where tb_follow.createby="'.$this->get['feed'].'" and tb_follow.`status`=2 and tb_product.delete=0 and tb_product.status=1
                        order by tb_product.createdate desc '.$limit;
             $arraydatalike=$this->db->db_set_recordset($sql);
             $strwhereproductid=0;
             if(count($arraydatalike))
             {
              $arraywhereproduct=array();
              foreach($arraydatalike as $valuedatalike)
              {
              $arraywhereproduct[]=$valuedatalike['productid'];
              
              }
              $strwhereproductid=join(",",$arraywhereproduct); 
             
             }
             
             $where[]=" tb_product.productid IN ( $strwhereproductid ) ";
             $limit='';
             
             }
            else if($this->get['fav'])
             {
             
             $sql="select productid from tb_like where tb_like.createby=".$this->get['fav']." and tb_like.status=2 order by createdate desc $limit";
             $arraydatalike=$this->db->db_set_recordset($sql);
             $strwhereproductid=0;
             if(count($arraydatalike))
             {
              $arraywhereproduct=array();
              foreach($arraydatalike as $valuedatalike)
              {
              $arraywhereproduct[]=$valuedatalike['productid'];
              
              }
              $strwhereproductid=join(",",$arraywhereproduct); 
             
             }
             //echo $sql;
             $where[]=" tb_product.productid IN ( $strwhereproductid ) ";
             $limit='';
             
             
             }
             
             else if($this->get['exifdatasearch'])
             {
             if($this->get['exifdatasearch']=='Model')
             {
             $exifdatawhere=$this->get['exifdatawhere'];
             $exifdatasearch=$this->get['exifdatasearch'];
             
             $strexif='"%'.$exifdatasearch.'\":\"'.$exifdatawhere.'%"';
             
             }else if($this->get['exifdatasearch']=="ISOSpeedRatings")
             {
             $exifdatawhere=$this->get['exifdatawhere'];
             $exifdatasearch=$this->get['exifdatasearch'];
             
             $strexif='"%'.$exifdatasearch.'\":'.$exifdatawhere.',%"';
             
             
             }
             else if($this->get['exifdatasearch']=='UndefinedTag:0xA434')
             {
             $exifdatawhere=str_replace('ppset','\\\\\\\\/',$this->get['exifdatawhere']);
             $exifdatasearch=$this->get['exifdatasearch'];
             
             $strexif='"%'.$exifdatasearch.'\":\"'.$exifdatawhere.'%"';
             
             }
             else
             {
             $exifdatawhere=str_replace('-','\\\\\\\\/',$this->get['exifdatawhere']);
             $exifdatasearch=$this->get['exifdatasearch'];
             
             $strexif='"%'.$exifdatasearch.'\":\"'.$exifdatawhere.'%"';
             
             }
             
             $whereroleid='';
             $innerjoinroleid='';
               if($this->get['roleid'])
             {
             $innerjoinroleid='inner join tb_user ON tb_user.userid=tb_product.createby  ';
             
             $whereroleid=" and  tb_user.roleid = ".$this->get['roleid']." "; 
             
             }
             
             
             $sql='SELECT
tb_plugins_imagewidth.productid
FROM
tb_plugins_imagewidth
INNER JOIN tb_img ON tb_plugins_imagewidth.imgmid = tb_img.imgmid
INNER JOIN tb_product ON tb_plugins_imagewidth.productid = tb_product.productid
'.$innerjoinroleid.'
where tb_product.status=1 and tb_product.`delete`=0   and tb_img.other like '.$strexif.' '.$whereroleid.'  GROUP BY tb_plugins_imagewidth.productid order by tb_product.createdate desc '.$limit;


             $arraydatalike=$this->db->db_set_recordset($sql);
             $strwhereproductid=0;
             if(count($arraydatalike))
             {
              $arraywhereproduct=array();
              foreach($arraydatalike as $valuedatalike)
              {
              $arraywhereproduct[]=$valuedatalike['productid'];
              
              }
              $strwhereproductid=join(",",$arraywhereproduct); 
             
             }
             
             $where[]=" tb_product.productid IN ( $strwhereproductid ) ";
             
             $limit='';
             
             
             
             }
             else if($this->get['trip'])
             {
             
             $where3=array();
             if($this->get['proid'])
             {
             $where3[]=" proid=".$this->get['proid'];
             
             }
             
             if($this->get['duid'])
             {
             $sql2="select value from tb_duration where duid=".$this->get['duid'];
             $arrayduration=$this->db->db_set_1recordrow($sql2);
             
             $where3[]=" day ".$arrayduration['value'];
             
             }
             
             
              if($this->get['budid'])
             {
             $sql2="select value from tb_budget where budid=".$this->get['budid'];
             $arraybudget=$this->db->db_set_1recordrow($sql2);
             
             $where3[]=" ( price ".$arraybudget['value']." or saleprice  ".$arraybudget['value']." ) ";
             
             }
             
             
             $where2=array();
             if($this->get['tagnamesearch'])
             {
               
               $arrtagname=explode(" ",$this->get['tagnamesearch']);
             
             $krow=0;
             $rowtagname=array();
             foreach($arrtagname as $valuetagname)
             {
             if(trim($valuetagname))
             {
            // $rowtagname[$krow]="'".$valuetagname."'";
             $where2[]=" tb_tag.name like '%".$valuetagname."%'";
             $krow++;
             }
             
             
             }
             
             
             $innerjoin2.=" inner join tb_relate_tag ON tb_product.productid=tb_relate_tag.productid ";
             $innerjoin2.=" inner join tb_tag ON tb_tag.tagid=tb_relate_tag.tagid ";
             $groupby2.=" group by tb_product.productid ";
             
             
           //  $where2[]=" tb_tag.name IN (".join("','",$rowtagname).")";
             
             
           }
             
             
             if(count($where2))
             {
               $where2=' and ('.join(" or ",$where2).')';
             
             }else
             {
              $where2="";
             
             }
             
             
             if(count($where3))
             {
               $where3=' where '.join(" and ",$where3);
             
             }else
             {
              $where3="";
             
             }
             
             
             $sql="SELECT tb_plugins_newtrip.productid FROM `tb_plugins_newtrip` 
             
             INNER JOIN (
             select tb_product.productid from tb_product
             $innerjoin2
             where tb_product.`delete`=0 
             $where2
             $groupby2

             ) tb_product ON tb_plugins_newtrip.productid=tb_product.productid 
             
             $where3
             
             ";
             
             
             $limit='';
             $arraydatalike=$this->db->db_set_recordset($sql);
             $strwhereproductid=0;
             if(count($arraydatalike))
             {
              $arraywhereproduct=array();
              foreach($arraydatalike as $valuedatalike)
              {
              $arraywhereproduct[]=$valuedatalike['productid'];
              
              }
              $strwhereproductid=join(",",$arraywhereproduct); 
             
             }
             
             $orderbyset="ORDER BY FIELD(productid,$strwhereproductid)";
             
             $where[]=" tb_product.productid IN ( $strwhereproductid ) ";
             
             
             
             }
             else
             {

             
             
             if($this->get['userid'])
             {
             $where[]=" tb_user.userid=".$this->get['userid'];
             if($this->get['userid']==$this->userdata['userid'])
             {
             
             $nodatacheckdate=0;
             
             }else
             {
             //$innerjoin.=" inner join tb_relate_tag ON tb_product.productid=tb_relate_tag.productid ";
             $userdata=$this->getuserbyuserid($this->get['userid'],' ,publish ');
             if($userdata['publish']==0)
             {
             if($this->userdata['oauth'])
             {
             
             
             $userdata=$this->getuserbyoauth($this->userdata['oauth']);
            if($userdata['roleid']=='3')
             {
             
             
             
             }else
             {
           
             $checkdata=$this->checkuserfollow($this->get['userid'],$this->userdata['oauth']);
             if($checkdata===true)
             {
             $where[]=" tb_product.status=1  ";
             
             }else
             {
             $where[]=" tb_user.publish=1  and tb_product.status=1";
             
             }
             
             }
             
             }else
             {
             
             $where[]="   tb_user.publish=1 ";
             
             
             }
             
             
             
             
             }else
             {
             
             
             
             
             
             $where[]=" tb_product.status=1  ";
             
             }
             
             
             }
             
             }else
             {
             
             
             if($this->userdata['oauth'])
             {
             $userdata=$this->getuserbyoauth($this->userdata['oauth']);
             

             if($userdata['roleid']=='3')
             {
             
             
             
             }else
             {
             
             $where[]=" tb_product.status=1  ";
             
             }
             
             
             
             }else
             {
             
             $where[]=" tb_product.status=1  ";
             
             }
             
             
             
             
             }
             
             
             
             }
             

              
              if($nodatacheckdate)
              {
              $where[]=" tb_product.createdate < '".date('Y-m-d H:i:s')."' "; 
              }
             
              
             if($this->get['search'])
             {
             $search=str_replace('#','',$this->get['search']) ;
             $sql='SELECT * from (

SELECT
tb_plugins_contact.productid
FROM
tb_plugins_contact
INNER JOIN (select productid from tb_product where tb_product.`delete`=0 and tb_product.`status`=1 ) as tb_product ON tb_plugins_contact.productid = tb_product.productid
LEFT JOIN tb_user ON tb_plugins_contact.sameaddressprofile = tb_user.userid
LEFT JOIN tb_province ON tb_user.proid = tb_province.proid
LEFT JOIN tb_district ON tb_user.disid = tb_district.disid
LEFT JOIN tb_tumbon ON tb_user.tumid = tb_tumbon.tumid
LEFT JOIN tb_province as  tb_province2 ON tb_plugins_contact.proid = tb_province2.proid
LEFT JOIN tb_district as  tb_district2 ON tb_plugins_contact.disid = tb_district2.disid
LEFT JOIN tb_tumbon as  tb_tumbon2 ON tb_plugins_contact.tumid = tb_tumbon2.tumid
where tb_tumbon.tumname like "%'.$search.'%" or tb_district.disname like "%'.$search.'%" or tb_province.proname like "%'.$search.'%" or tb_tumbon2.tumname like "%'.$search.'%" or tb_district2.disname like "%'.$search.'%" or tb_province2.proname like "%'.$search.'%"

UNION ALL


SELECT
tb_product.productid
FROM
tb_relate_tag
INNER JOIN tb_tag ON tb_tag.tagid = tb_relate_tag.tagid
INNER JOIN tb_product ON tb_relate_tag.productid = tb_product.productid
where (tb_product.`delete`=0 and tb_product.`status`=1) and (tb_tag.`name` like "%'.$search.'%" or tb_product.title like "%'.$search.'%" or tb_product.description like "%'.$search.'%"  ) 
) tb_product GROUP BY productid  '.$limit;
             $arraydatalike=$this->db->db_set_recordset($sql);
             //echo $sql;
             $strwhereproductid=0;
             if(count($arraydatalike))
             {
              $arraywhereproduct=array();
              foreach($arraydatalike as $valuedatalike)
              {
              $arraywhereproduct[]=$valuedatalike['productid'];
              
              }
              $strwhereproductid=join(",",$arraywhereproduct); 
             
             }
             
             $where[]=" tb_product.productid IN ( $strwhereproductid ) ";
             $limit='';
             }
             
             if(count($this->get['tagid']))
             {
             $innerjoin.=" inner join tb_relate_tag ON tb_product.productid=tb_relate_tag.productid ";
             $groupby.=" group by tb_product.productid ";
             
             if($this->get['tagid'][0])
             {
             $where[]=" tb_relate_tag.tagid IN (".join(",",$this->get['tagid']).")";
             }else
             {
             $where[]=" tb_relate_tag.tagid IN (0)";
             
             }
             
             
             
             
             }
             
             
             if($this->get['tagnamesearchdata'])
             {
             
             
             $innerjoin.=" inner join tb_relate_tag ON tb_product.productid=tb_relate_tag.productid ";
             $innerjoin.=" inner join tb_tag ON tb_tag.tagid=tb_relate_tag.tagid ";
             $groupby.=" group by tb_product.productid ";
             
             $arraychecktag=explode("|",$this->get['tagnamesearchdata']);
             $arraynewchecktagh=array();
             if(count($arraychecktag))
             {
             $k=0;
             foreach($arraychecktag as $valuedatac)
             {
             if(trim($valuedatac))
             {
             $arraynewchecktagh[$k]=$valuedatac;
             $k++;
             }
             
             
             
             }
             
             }
             $where5=array();
             if(count($arraynewchecktagh))
             {
             foreach($arraynewchecktagh as $valuetagdata)
             {
             $where5[]=" tb_tag.name ='".$valuetagdata."'";
             
             }
             
             }
             
             if(count($where5))
             {
             
             $strset=join(" or ",$where5);
             $where[]=' ('.$strset.' ) ';
             }
             
             
//             if($this->get['tagid'][0])
//             {
//             $where[]=" tb_relate_tag.tagid IN (".join(",",$this->get['tagid']).")";
//             }else
//             {
//             $where[]=" tb_relate_tag.tagid IN (0)";
//             
//             }
             
             
             
             
             }
             
          
             
            
             
             if($this->get['lat']&&$this->get['lng'])
             {
                    $lat=$this->get['lat'];
                    $lng=$this->get['lng'];
                    if($this->get['distance'])
                    {
                    $lamda=$this->get['distance']/111.16581;
                    
                    }else
                    {
                    
                    $lamda=10/111.16581;
                    }
                    
             $where2=array();       
             if(count($this->get['tagname']))
             {
             $krow=0;
             $rowtagname=array();
             foreach($this->get['tagname'] as $valuetagname)
             {
             if(trim($valuetagname))
             {
            // $rowtagname[$krow]="'".$valuetagname."'";
             $where2[]=" tb_tag.name='".$valuetagname."'";
             $krow++;
             }
             
             
             }
             
             
             $innerjoin2.=" inner join tb_relate_tag ON tb_product.productid=tb_relate_tag.productid ";
             $innerjoin2.=" inner join tb_tag ON tb_tag.tagid=tb_relate_tag.tagid ";
             $groupby2.=" group by tb_product.productid ";
             
             
           //  $where2[]=" tb_tag.name IN (".join("','",$rowtagname).")";
             
             
             }
             
             if(count($where2))
             {
               $where2=' and ('.join(" or ",$where2).')';
             
             }else
             {
              $where2="";
             
             }
             
                    
                    $sql="SELECT
tb_plugins_map.lat,
tb_plugins_map.lng,
tb_plugins_map.mapid,
 POWER((tb_plugins_map.lat-".$lat."),2)+POWER(COS(RADIANS((tb_plugins_map.lat+".$lat.")/2)) * (tb_plugins_map.lng-".$lng."),2) AS distance,
tb_plugins_map.productid
FROM
tb_plugins_map
INNER JOIN (

select tb_product.productid from tb_product
$innerjoin2
where tb_product.`delete`=0 
$where2
$groupby2

) tb_product ON tb_plugins_map.productid=tb_product.productid
where tb_plugins_map.lat between ".(-$lamda+$lat)." AND ".($lamda+$lat)." AND tb_plugins_map.lng between ".(-$lamda+$lng)." AND ".($lamda+$lng)."GROUP BY tb_plugins_map.productid order by distance asc ".$limit;

             $limit='';
             $arraydatalike=$this->db->db_set_recordset($sql);
             $strwhereproductid=0;
             if(count($arraydatalike))
             {
              $arraywhereproduct=array();
              foreach($arraydatalike as $valuedatalike)
              {
              $arraywhereproduct[]=$valuedatalike['productid'];
              
              }
              $strwhereproductid=join(",",$arraywhereproduct); 
             
             }
             
             $orderbyset="ORDER BY FIELD(tb_product.productid,$strwhereproductid)";
             
             $where[]=" tb_product.productid IN ( $strwhereproductid ) ";
             
             
             }
             
             if($this->get['type']&&$this->get['type']!='All')
             {
                if($this->get['type']=='PDF')
                {
                $innerjoin.=" inner join tb_plugins_upload ON tb_product.productid=tb_plugins_upload.productid ";
                $groupby.=" group by tb_product.productid ";
                
                }else if($this->get['type']=='RMC')
                {
                $innerjoin.=" inner join tb_plugins_upload_book ON tb_product.productid=tb_plugins_upload_book.productid ";
                $groupby.=" group by tb_product.productid ";
                
                }else if($this->get['type']=='MP4')
                {
                $innerjoin.=" inner join tb_plugins_vdoupload ON tb_product.productid=tb_plugins_vdoupload.productid ";
                $groupby.=" group by tb_product.productid ";
                
                }
             
             
             
             }
             
             
             if(count($where))
             {
               $where=' where '.join(" and ",$where);
             
             }else
             {
              $where="";
             
             }

             $select="";
             if($this->get['orderby'])
             {
             
              if($this->get['orderby']==1)
             {
             $select.=" ,(select count(tb_fav.favid) as countfav from tb_fav where  tb_product.productid=tb_fav.productid   )  as countlike ";
             $orderby=' order by countlike desc  ';
          //   $groupby=' GROUP BY tb_fav.productid ';
         //    $innerjoin.=" LEFT join tb_fav ON tb_product.productid=tb_fav.productid  ";
             
             }else if($this->get['orderby']==3)
             {
             $orderby=' order by rand()';
             
             }
             
             else
             {
             $orderby=' order by '.$this->get['orderby'];
             }
             
             
             
             
             
             
             }else
             {
             
             if($this->get['lat']&&$this->get['lng'])
             {
             $orderby=$orderbyset;
             }else
             {
             $orderby=1;
             }
             
             }
             

             $nomemcache=0;
             if($this->get['nocache'])
             {
             $nomemcache=1;
             
             }
             
             
             
             $arraydata=$this->getproductbycondition($where,$limit,$orderby,$innerjoin,$groupby,$select,$nomemcache);
             
             
             
              
             $this->arraydata['data']=$arraydata;
             
             $sql=" select count(tb_product.productid) as countproduct  from tb_product 
            inner join tb_user ON tb_user.userid=tb_product.createby  
            $innerjoin
            $where 
            $groupby 
            ";
            $datarow=$this->db->db_set_1recordrow($sql);
             
             $this->arraydata['total']= intval($datarow['countproduct']);
             $this->arraydata['page']= ceil($this->arraydata['total']/countpage);
             $this->arraydata['next']="";
             $this->arraydata['back']="";
              if($this->get['page']>1)
             {
             $set2=1;
             $this->get['page']=$this->get['page']-1;
             $this->arraydata['back']=baseinfo.'/ajax/getproduct'.'?'.http_build_query($this->get);
             
             
             }
             
             
             
             if(count($this->arraydata['data'])==countpage)
             {
             if($set2==1)
             {
             $count=2;
             }else
             {
             $count=1;  
             }
             
             $this->get['page']=$this->get['page']+$count;
             
             
             $this->arraydata['next']=baseinfo.'/ajax/getproduct'.'?'.http_build_query($this->get);
             
             }
            
             
            
            
            }
            
            function gettaguserproduct()
            {
            
            
            
            }
            
            function getproductlist()
            {
            

              $where=array();
              $limit="";
              $innerjoin="";
              $groupby="";
             if($this->get['productid'])
             {
             
             
             
             $where[]=" productid=".$this->get['productid'];
             $limit="limit  0,1";
             
             }
             
             if($this->get['fid'])
             {
             $where[]=" fid=".$this->get['fid'];
             
             }
             
              if($this->get['nopoi']==1)
              {
              $where[]=" ispoi=1 ";
              }
              
             
             
            
             
             if($this->get['page'])
             {
             $page=$this->get['page'];
             $page=(($page - 1) * 100);
             $limit="limit  $page,100";
             
             }else
             {
             $page=0;
             $limit="limit  $page,".countpage;
             }
             $where[]=" tb_product.delete=0 ";
             if($this->get['feed'])
             {
             $sql='SELECT
                        tb_product.productid
                        FROM
                        tb_follow
                        INNER JOIN tb_product ON tb_follow.userid = tb_product.createby
                        where tb_follow.createby="'.$this->get['feed'].'" and tb_follow.`status`=2 and tb_product.delete=0 and tb_product.status=1
                        order by tb_product.createdate desc '.$limit;
             $arraydatalike=$this->db->db_set_recordset($sql);
             $strwhereproductid=0;
             if(count($arraydatalike))
             {
              $arraywhereproduct=array();
              foreach($arraydatalike as $valuedatalike)
              {
              $arraywhereproduct[]=$valuedatalike['productid'];
              
              }
              $strwhereproductid=join(",",$arraywhereproduct); 
             
             }
             
             $where[]=" tb_product.productid IN ( $strwhereproductid ) ";
             $limit='';
             
             }
            else if($this->get['fav'])
             {
             
             $sql="select productid from tb_like where tb_like.createby=".$this->get['fav']." and tb_like.status=2 order by createdate desc $limit";
             $arraydatalike=$this->db->db_set_recordset($sql);
             $strwhereproductid=0;
             if(count($arraydatalike))
             {
              $arraywhereproduct=array();
              foreach($arraydatalike as $valuedatalike)
              {
              $arraywhereproduct[]=$valuedatalike['productid'];
              
              }
              $strwhereproductid=join(",",$arraywhereproduct); 
             
             }
             
             $where[]=" tb_product.productid IN ( $strwhereproductid ) ";
             
             
             
             }
             else
             {
             if($this->get['userid'])
             {
             $where[]=" tb_user.userid=".$this->get['userid'];
             if($this->get['userid']==$this->userdata['userid'])
             {
             
             
             
             }else
             {
             //$innerjoin.=" inner join tb_relate_tag ON tb_product.productid=tb_relate_tag.productid ";
             $userdata=$this->getuserbyuserid($this->get['userid'],' ,publish ');
             if($userdata['publish']==0)
             {
             if($this->userdata['oauth'])
             {
             
             
             $checkdata=$this->checkuserfollow($this->get['userid'],$this->userdata['oauth']);
             if($checkdata===true)
             {
             $where[]=" tb_product.status=1  ";
             
             }else
             {
             $where[]=" tb_user.publish=1  ";
             
             }
             
             }else
             {
             
             $where[]="   tb_user.publish=1 ";
             
             
             }
             }else
             {
             $where[]=" tb_product.status=1  ";
             
             }
             
             
             }
             
             }else
             {
             $where[]=" tb_product.status=1  ";
             }
             }
             
             if($this->get['search'])
             {
             $search=str_replace('#','',$this->get['search']) ;
             $sql='SELECT * from (

SELECT
tb_plugins_contact.productid
FROM
tb_plugins_contact
INNER JOIN (select productid from tb_product where tb_product.`delete`=0 ) as tb_product ON tb_plugins_contact.productid = tb_product.productid
LEFT JOIN tb_user ON tb_plugins_contact.sameaddressprofile = tb_user.userid
LEFT JOIN tb_province ON tb_user.proid = tb_province.proid
LEFT JOIN tb_district ON tb_user.disid = tb_district.disid
LEFT JOIN tb_tumbon ON tb_user.tumid = tb_tumbon.tumid
LEFT JOIN tb_province as  tb_province2 ON tb_plugins_contact.proid = tb_province2.proid
LEFT JOIN tb_district as  tb_district2 ON tb_plugins_contact.disid = tb_district2.disid
LEFT JOIN tb_tumbon as  tb_tumbon2 ON tb_plugins_contact.tumid = tb_tumbon2.tumid
where tb_tumbon.tumname like "%'.$search.'%" or tb_district.disname like "%'.$search.'%" or tb_province.proname like "%'.$search.'%" or tb_tumbon2.tumname like "%'.$search.'%" or tb_district2.disname like "%'.$search.'%" or tb_province2.proname like "%'.$search.'%"

UNION ALL


SELECT
tb_product.productid
FROM
tb_relate_tag
INNER JOIN tb_tag ON tb_tag.tagid = tb_relate_tag.tagid
INNER JOIN tb_product ON tb_relate_tag.productid = tb_product.productid
where tb_product.`delete`=0 and (tb_tag.`name` like "%'.$search.'%" or tb_product.title like "%'.$search.'%" or tb_product.description like "%'.$search.'%"  ) 
) tb_product GROUP BY productid  '.$limit;
             $arraydatalike=$this->db->db_set_recordset($sql);
             //echo $sql;
             $strwhereproductid=0;
             if(count($arraydatalike))
             {
              $arraywhereproduct=array();
              foreach($arraydatalike as $valuedatalike)
              {
              $arraywhereproduct[]=$valuedatalike['productid'];
              
              }
              $strwhereproductid=join(",",$arraywhereproduct); 
             
             }
             
             $where[]=" tb_product.productid IN ( $strwhereproductid ) ";
             $limit='';
             }
             
             if(count($this->get['tagid']))
             {
             $innerjoin.=" left join tb_relate_tag ON tb_product.productid=tb_relate_tag.productid ";
             $groupby.=" group by tb_product.productid ";
             $where[]=" tb_relate_tag.tagid IN (".join(",",$this->get['tagid']).")";
             
             
             }
             
            
             
             if($this->get['lat']&&$this->get['lng'])
             {
                    $lat=$this->get['lat'];
                    $lng=$this->get['lng'];
                    if($this->get['distance'])
                    {
                    $lamda=$this->get['distance']/111.16581;
                    
                    }else
                    {
                    
                    $lamda=10/111.16581;
                    }
                    
             $where2=array();       
             if(count($this->get['tagname']))
             {
             $krow=0;
             $rowtagname=array();
             foreach($this->get['tagname'] as $valuetagname)
             {
             if(trim($valuetagname))
             {
            // $rowtagname[$krow]="'".$valuetagname."'";
             $where2[]=" tb_tag.name='".$valuetagname."'";
             $krow++;
             }
             
             
             }
             
             
             $innerjoin2.=" inner join tb_relate_tag ON tb_product.productid=tb_relate_tag.productid ";
             $innerjoin2.=" inner join tb_tag ON tb_tag.tagid=tb_relate_tag.tagid ";
             $groupby2.=" group by tb_product.productid ";
             
             
           //  $where2[]=" tb_tag.name IN (".join("','",$rowtagname).")";
             
             
             }
             
             if(count($where2))
             {
               $where2=' and ('.join(" or ",$where2).')';
             
             }else
             {
              $where2="";
             
             }
             
                    
                    $sql="SELECT
tb_plugins_map.lat,
tb_plugins_map.lng,
tb_plugins_map.mapid,
 POWER((tb_plugins_map.lat-".$lat."),2)+POWER(COS(RADIANS((tb_plugins_map.lat+".$lat.")/2)) * (tb_plugins_map.lng-".$lng."),2) AS distance,
tb_plugins_map.productid
FROM
tb_plugins_map
INNER JOIN (

select tb_product.productid from tb_product
$innerjoin2
where tb_product.`delete`=0 
$where2
$groupby2

) tb_product ON tb_plugins_map.productid=tb_product.productid
where tb_plugins_map.lat between ".(-$lamda+$lat)." AND ".($lamda+$lat)." AND tb_plugins_map.lng between ".(-$lamda+$lng)." AND ".($lamda+$lng)."GROUP BY tb_plugins_map.productid order by distance asc ".$limit;
//echo $sql;
             $limit='';
             $arraydatalike=$this->db->db_set_recordset($sql);
             $strwhereproductid=0;
             if(count($arraydatalike))
             {
              $arraywhereproduct=array();
              foreach($arraydatalike as $valuedatalike)
              {
              $arraywhereproduct[]=$valuedatalike['productid'];
              
              }
              $strwhereproductid=join(",",$arraywhereproduct); 
             
             }
             
             $orderbyset="ORDER BY FIELD(productid,$strwhereproductid)";
             
             $where[]=" tb_product.productid IN ( $strwhereproductid ) ";
             
             
             }
             
             
             if(count($where))
             {
               $where=' where '.join(" and ",$where);
             
             }else
             {
              $where="";
             
             }
             $select="";
             if($this->get['orderby'])
             {
             
              if($this->get['orderby']==1)
             {
             $select.=" ,count(tb_fav.productid) as countlike ";
             $orderby=' order by countlike desc  ';
             $groupby=' GROUP BY tb_fav.productid ';
             $innerjoin.=" LEFT join tb_fav ON tb_product.productid=tb_fav.productid  ";
             
             }else
             {
             $orderby=' order by '.$this->get['orderby'];
             }
             
             
             
             
             }else
             {
             if($this->get['lat']&&$this->get['lng'])
             {
             $orderby=$orderbyset;
             }else
             {
             $orderby=1;
             }
             
             }
             
             $arraydata=$this->getproductbycondition($where,$limit,$orderby,$innerjoin,$groupby,$select);
              
             $this->arraydata['data']=$arraydata;
             $this->arraydata['next']="";
             $this->arraydata['back']="";
              if($this->get['page']>1)
             {
             $set2=1;
             $this->get['page']=$this->get['page']-1;
             $this->arraydata['back']=baseinfo.'/ajax/getproduct'.'?'.http_build_query($this->get);
             
             
             }
             
             
             
             if(count($this->arraydata['data'])==countpage)
             {
             if($set2==1)
             {
             $count=2;
             }else
             {
             $count=1;  
             }
             
             $this->get['page']=$this->get['page']+$count;
             
             
             $this->arraydata['next']=baseinfo.'/ajax/getproduct'.'?'.http_build_query($this->get);
             
             }
            
             
            
            
            }
            
            function savefeaturepoint()
            {
            
            $oauth=$this->userdata['oauth'];
             $arrayuser=$this->getuserbyoauth($oauth);

            if($this->post['productid']&&($arrayuser['roleid']==3||$arrayuser['roleid']==4))
            {
            
            $sql="delete from tb_product_point where tb_product_point.productid=".$this->post['productid'];
           // echo $sql;
            $this->db->db_set_execute($sql);
            if(count($this->post['featureset']))
            {
            foreach($this->post['featureset'] as $valuefid)
            {
            $arraydata=array();
            $arraydata['fid']=$valuefid;
            $arraydata['productid']=$this->post['productid'];
            
            
            $sql='select pointid from tb_notification where pointid='.$this->post['productid'];
            
            $arraycheck=$this->db->db_set_1recordrow($sql);
            if($arraycheck['pointid'])
            {
            
            
            }else
            {
            
           $sql="select tb_product.productid,tb_product.title,tb_product.createby from tb_product   where tb_product.productid=".$this->post['productid'];
           $dataproduct=$this->db->db_set_1recordrow($sql);  
           $userid=$dataproduct['createby']; 
           $arraydataset['userid']=$userid;
           $arraydataset['createby']=$arrayuser['userid'];
           $arraydataset['conid']=45;
           $arraydataset['pointid']=$this->post['productid'];
           $notiid[$userid]=$this->savenotificationlist($arraydataset);
            
           $msgto=$arrayuser['displayname'].' '.$this->getconditionmsgbyid(45).' '.$dataproduct['title'];
           $arraydatanow[]=$userid;
           $this->sendtonotification($arraydatanow,$msgto,$notiid);
            
            }
            
            $this->db->db_set($arraydata,'tb_product_point');
            
            
            
            }
            
            
            }
            
            
            
            
            }
            
            }
            
            function savestickypost()
            {
            
             $oauth=$this->userdata['oauth'];
             $arrayuser=$this->getuserbyoauth($oauth);

            if($this->post['productid']&&($arrayuser['roleid']==3||$arrayuser['roleid']==4))
            {
            $sql='select fid,position from tb_product where productid='.$this->post['productid'];
            $arraydata1=$this->db->db_set_1recordrow($sql);
            if($arraydata1['position'])
            {
            
            $arraydata['position']=0;
            $this->db->db_set($arraydata,'tb_product',' productid='.$this->post['productid']);
            
            
            }else
            {
            $sql='select max(position) as maxpostion from tb_product where fid='.$arraydata1['fid'];
            $arraydata2=$this->db->db_set_1recordrow($sql);
            
            
            
            $arraydata['position']=intval($arraydata2['maxpostion'])+1;
            $this->db->db_set($arraydata,'tb_product',' productid='.$this->post['productid']);
            
            
            $sql='select position,productid from tb_product where fid='.$arraydata1['fid'].' and position>0 order by position asc';
            $arrayall=$this->db->db_set_recordset($sql);
            if(count($arrayall))
            {
            $row=1;
            foreach($arrayall as $valueall)
            {
            $arraycheck['position']=$row;
            $this->db->db_set($arraycheck,'tb_product',' productid='.$valueall['productid']);
            
            $row++;
            
            
            }
            }
            
            }
            
            
            
            
            
            
            
            }
            
            }
            
            function getfeaturepoint()
            {
            
            if($this->get['productid'])
            {
            $sql='SELECT
tb_product_point.pointid,
tb_product_point.fid,
tb_product_point.productid
FROM
tb_product_point
where productid='.$this->get['productid'].'
';
           $this->arraydata['data']=$this->db->db_set_recordset($sql);
            
            }
            
            
            }
            
            function getmypointhistory()
            {
             $oauth=$this->userdata['oauth'];
             $arrayuser=$this->getuserbyoauth($oauth);

            if($arrayuser['userid']&&$this->get['page'])
            {
            $page=$this->get['page'];
             $page=(($page - 1) * 5);
             $limit="limit  $page,".'5';
            $sql='SELECT *,DATE_FORMAT(tb_product_point_history.createdate,\'%d/%m/%Y\') as newdate from tb_product_point_history where createby='.$arrayuser['userid'].' order by tb_product_point_history.createdate desc';
            $this->arraydata['data']=$this->db->db_set_recordset($sql);
            
            
             if($this->get['page']=='1')
            {
            
            $sql='SELECT count(tb_product_point_history.pointhid) as countorder from tb_product_point_history where tb_product_point_history.createby='.$arrayuser['userid'];
            $arraycount=$this->db->db_set_1recordrow($sql);
            $this->arraydata['count']=intval($arraycount['countorder']);
            }
            
            
            }
            
            
            
            }
            
            function getmyorderlist()
            {
            
              $oauth=$this->userdata['oauth'];
             $arrayuser=$this->getuserbyoauth($oauth);

            if($arrayuser['userid']&&$this->get['page'])
            {
              $page=$this->get['page'];
             $page=(($page - 1) * 5);
             $limit="limit  $page,".'5';
             $where='';
             if($this->get['status'])
             {
             $where=' and tb_product_order.`status`='.$this->get['status'];
             }
            $sql='SELECT
DATE_FORMAT(tb_product_order.createdate,\'%T %d/%m/%Y\') as newdate,            
tb_product_order.orderid,
tb_product_order.point,
tb_product_order.`status`,
tb_product_order.sumall,
tb_product_order.cash,
tb_product_order.`change`,
tb_product_order.userid,
tb_product_order.payid,
tb_product_order.tspoid,
tb_product_order.tfid,
tb_product_order.cart,
tb_product_order.cartstatus,
tb_product_order.updateby,
tb_product_order.createby,
tb_product_order.updatedate,
tb_product_order.createdate,
IF (tb_product_setting.shopname is NULL,tb_user.displayname,tb_product_setting.shopname) as displayname,
IF (tb_product_setting.orderprefix is NULL,\'\',tb_product_setting.orderprefix) as orderprefix,
tb_user.username
FROM
tb_product_order
INNER JOIN tb_user ON tb_product_order.createby = tb_user.userid
LEFT JOIN tb_product_setting ON tb_user.userid = tb_product_setting.createby
where tb_product_order.userid='.$arrayuser['userid'].' '.$where.' order by tb_product_order.createdate desc '.$limit;
            $arraymyorder=$this->db->db_set_recordset($sql);
            $this->arraydata['data']=$arraymyorder;
            if($this->get['page']=='1')
            {
            
            $sql='SELECT count(tb_product_order.orderid) as countorder from tb_product_order where tb_product_order.userid='.$arrayuser['userid'].' '.$where;
            $arraycount=$this->db->db_set_1recordrow($sql);
            $this->arraydata['count']=intval($arraycount['countorder']);
            }
            
            
            }
            
            
            }
            
            function saverefnocart()
            {
            $oauth=$this->userdata['oauth'];
           $arrayuser=$this->getuserbyoauth($oauth);

            if($arrayuser['userid']&&$this->post['orderid']&&$this->post['code']&&($arrayuser['roleid']=='2'||$arrayuser['roleid']=='3'||$arrayuser['roleid']=='4'||$arrayuser['roleid']=='5'))
            {
            $arraydata['code']=$this->post['code'];
            $arraydata['note']=$this->post['note'];
            $arraydata['orderid']=$this->post['orderid'];
            $arraydata['createby']=$arrayuser['userid'];
            $arraydata['createdate']=date("Y-m-d H:i:s");
            $this->db->db_set($arraydata,'tb_product_shipping');
            
            }
            
            }
            
            function updatestatuscart()
           {
           $oauth=$this->userdata['oauth'];
           $arrayuser=$this->getuserbyoauth($oauth);

            if($arrayuser['userid']&&$this->post['orderid']&&$this->post['status']&&($arrayuser['roleid']=='2'||$arrayuser['roleid']=='3'||$arrayuser['roleid']=='4'||$arrayuser['roleid']=='5'))
            {
            $arraydata['status']=$this->post['status'];
            
            $this->db->db_set($arraydata,'tb_product_order','createby='.$arrayuser['userid'].' and orderid='.$this->post['orderid']);
            $orderid=$this->post['orderid'];
            
             $sql='select 

IF (tb_product_setting.orderprefix is NULL,\'\',tb_product_setting.orderprefix) as orderprefix

from tb_user 

 LEFT JOIN tb_product_setting ON tb_user.userid = tb_product_setting.createby

 where tb_user.userid='.$arrayuser['userid'];
            $arraysetting=$this->db->db_set_1recordrow($sql);
            
            $sql='select userid from tb_product_order where orderid='.$orderid;
            
            $arrayproduct=$this->db->db_set_1recordrow($sql);
            
            if($arraydata['status']=='2')
            {
            
            $this->sendemailpaybyorderid($this->post['orderid']);
            
            
            
           $msgto='ได้รับยอดเงินเรียบร้อยแล้ว‏ (Order Id:'.$arraysetting['orderprefix'].$orderid.')';       
           $userid=$arrayproduct['userid'];
           $arraydataset['userid']=$userid;
           $arraydataset['createby']=$arrayuser['userid'];
           $arraydataset['conid']=0;
           $arraydataset['smsgid']=$this->savesupermsg($msgto,0,$orderid,1);
           $notiid[$userid]=$this->savenotificationlist($arraydataset);
    
            $arraydatanow[]=$userid;
            $this->sendtonotification($arraydatanow,$msgto,$notiid);
            
            
            
            }else if($arraydata['status']=='3')
            {
            
            
            $this->sendemailshipbyorderid($this->post['orderid']);
            
            
            
           $msgto='จัดส่งสินค้าให้ท่านแล้ว  (Order Id:'.$arraysetting['orderprefix'].$orderid.')';       
           $userid=$arrayproduct['userid'];
           $arraydataset['userid']=$userid;
           $arraydataset['createby']=$arrayuser['userid'];
           $arraydataset['conid']=0;
           $arraydataset['smsgid']=$this->savesupermsg($msgto,0,$orderid,1);
           $notiid[$userid]=$this->savenotificationlist($arraydataset);
    
            $arraydatanow[]=$userid;
            $this->sendtonotification($arraydatanow,$msgto,$notiid);
            
            
            
            
            }
            else if($arraydata['status']=='4')
            {
            
            
            $this->sendemailcancelbyorderid($this->post['orderid']);
            
            
           $msgto='ยกเลิกรายการสั่งซื้อแล้ว  (Order Id:'.$arraysetting['orderprefix'].$orderid.')';       
           $userid=$arrayproduct['userid'];
           $arraydataset['userid']=$userid;
           $arraydataset['createby']=$arrayuser['userid'];
           $arraydataset['conid']=0;
           $arraydataset['smsgid']=$this->savesupermsg($msgto,0,$orderid,1);
           $notiid[$userid]=$this->savenotificationlist($arraydataset);
    
            $arraydatanow[]=$userid;
            $this->sendtonotification($arraydatanow,$msgto,$notiid);
            
            
            }
            
            
            }
          
            }
            
            function getshopmyorderlist()
            {
            
              $oauth=$this->userdata['oauth'];
             $arrayuser=$this->getuserbyoauth($oauth);

            if($arrayuser['userid']&&$this->get['page']&&($arrayuser['roleid']=='3'||$arrayuser['roleid']=='4'||$arrayuser['roleid']=='5'))
            {
              $page=$this->get['page'];
             $page=(($page - 1) * 5);
             $limit="limit  $page,".'5';
             $where='';
             if($this->get['status'])
             {
             $where=' and tb_product_order.`status`='.$this->get['status'];
             }
            $sql='SELECT
DATE_FORMAT(tb_product_order.createdate,\'%T %d/%m/%Y\') as newdate,            
tb_product_order.orderid,
tb_product_order.point,
tb_product_order.`status`,
tb_product_order.sumall,
tb_product_order.cash,
tb_product_order.`change`,
tb_product_order.userid,
tb_product_order.payid,
tb_product_order.tspoid,
tb_product_order.tfid,
tb_product_order.cart,
tb_product_order.cartstatus,
tb_product_order.updateby,
tb_product_order.createby,
tb_product_order.updatedate,
tb_product_order.createdate,
tb_user.displayname,
IF (tb_product_setting.orderprefix is NULL,\'\',tb_product_setting.orderprefix) as orderprefix,
tb_user.username
FROM
tb_product_order
INNER JOIN tb_user ON tb_product_order.userid = tb_user.userid
LEFT JOIN tb_product_setting ON tb_product_order.createby = tb_product_setting.createby
where tb_product_order.createby='.$arrayuser['userid'].' '.$where.' '.$limit;
            $arraymyorder=$this->db->db_set_recordset($sql);
            $this->arraydata['data']=$arraymyorder;
            if($this->get['page']=='1')
            {
            
            $sql='SELECT count(tb_product_order.orderid) as countorder from tb_product_order where tb_product_order.createby='.$arrayuser['userid'].' '.$where;
            $arraycount=$this->db->db_set_1recordrow($sql);
            $this->arraydata['count']=intval($arraycount['countorder']);
            }
            
            
            }
            
            
            }
            
            
            function testlocationdata()
            {
            
            if($this->get['lat']&&$this->get['lng'])
            {
            $arraydata=array();
            $arraydata['test']=$this->get['lat'].','.$this->get['lng'].'=>ip=>'.$_SERVER["REMOTE_ADDR"];
            $this->db->db_set($arraydata,'tb_log');
            
            
            
            
            }
            
            }
            
            function gettagproduct()
            {
             if($this->get['tag'])
             {
              if($this->get['page'])
             {
             $page=$this->get['page'];
             $page=(($page - 1) * countpage);
             $limit="limit  $page,".countpage;
             
             }else
             {
             $page=0;
             $limit="limit  $page,".countpage;
             }
             
             if($this->get['fid'])
             {
             $where[]=" fid=".$this->get['fid'];
             
             }
             
             $where[]=" tb_product.delete=0 ";
             $where[]=" tb_product.createby=".$this->get['tag']." ";
             
             if(count($where))
             {
             $where=' where '.join(' and ',$where);
             
             }
             $sql="SELECT
             tb_tag.`name`,
             tb_tag.tagid
             FROM
             tb_relate_tag
             INNER JOIN (select productid,createdate from tb_product $where ) tb_product ON tb_product.productid =  tb_relate_tag.productid
             INNER JOIN tb_tag ON tb_relate_tag.tagid = tb_tag.tagid
             group by tagid
             order by tb_product.createdate desc
             $limit
             ";
             
             $data=$this->db->db_set_recordset($sql);
             $arraynewdata=array();
             if(count($data))
            {
            foreach($data as $valuedata)
            {
            $sql="select simgmid from (select simgmid,productid,createdate from tb_product $where ) tb_product INNER JOIN tb_relate_tag on tb_relate_tag.productid=tb_product.productid  where tb_relate_tag.tagid=".$valuedata['tagid'].'     order by tb_product.createdate desc  limit 0,3';
            
            $data2=$this->db->db_set_recordset($sql);
            if(count($data2))
            {
            foreach($data2 as $valuedata2)
            {
            $valuedata['arrayimg'][]= $this->getimagebyimgmid($valuedata2['simgmid']);
            }
            }
            
            
            
             $sql="select count(tb_product.productid) as countprouduct from  (select productid from tb_product $where ) tb_product INNER JOIN tb_relate_tag on tb_relate_tag.productid=tb_product.productid  where tb_relate_tag.tagid=".$valuedata['tagid'].'    ';
            $data3=$this->db->db_set_1recordrow($sql);
            $valuedata['countprouduct']=intval($data3['countprouduct']);
            
            
            $arraynewdata[]=$valuedata;
            
            }
            
           
            
            }
             $this->arraydata['data']=$arraynewdata;
             
             }
             
            
            }
            
            function likeproduct()
            {

            if($this->post['productid']&&$this->userdata['oauth'])
            {
            
              $boolean=$this->likefunction($this->post['productid'],$this->userdata['oauth']);
              if($boolean)
              {
               $this->arraydata['data']['countlike']=$this->countlike($this->post['productid']);
               $this->arraydata['data']['checklike']=$this->checkuserlike($this->post['productid'],$this->userdata['oauth']);
              
              }else
              {
              $this->arraydata['error'][]=24;   
              
              }
             
            
            }else
            {
            $this->arraydata['error'][]=5;
            
            }
            
            
            
            }
            
            function savesetting()
            {
                    if($this->userdata['oauth'])
                    {
                 //  $datalog['test']=json_encode($this->post);
//                    $this->db->db_set($datalog,"tb_logtest");
                    $userdata=$this->getuserbyoauth($this->userdata['oauth'],',email,password,emailfacebook');
                    if($userdata['userid'])
                    {
                       $userid=$userdata['userid'];
                       if($this->post['filter']==1)
                       {
                       
                       $data=$this->post;
                       unset($data['filelink']);
                       
                       unset($data['filelink']);
                       
                       
                       unset($data['filter']);
                       unset($data['height']);
                       unset($data['width']);
                       unset($data['fileold']);
                       unset($data['heightcrop']);
                       unset($data['widthcrop']);
                       unset($data['filelinkcrop']);
                       unset($data['photobanner']);
                       unset($data['photomain']);
                       unset($data['oauth']);
                       unset($data['infoid']);
                       unset($data['token']);
                       unset($data['qstrgt']);
                       
                       
                       
                       unset($data['serialnumber']);
                       
                       unset($data['income']);
                       unset($data['education']);
                       unset($data['like']);
                       unset($data['modelother']);
                       
                       
                       unset($data['modelnumber']);
                       unset($data['modelnumber']);
                       unset($data['username_signup']);
                       unset($data['password_signup']);
                       unset($data['repassword_signup']);
                       unset($data['email_signup']);
                       
                       unset($data['username_login']);
                       unset($data['password_login']);
                       unset($data['nochecksameaddress']);
                       
                       
                   //    unset($data['dayBirthtext']);
                       
                       
                        if($this->post['hideemail'])
                       {
                       $data['hideemail']=1;
                       
                       
                       }else
                       {
                       
                       $data['hideemail']=0;
                       }
                       
                       
                       
                       if($this->post['hidephone'])
                       {
                       $data['hidephone']=1;
                       
                       
                       }else
                       {
                       
                       $data['hidephone']=0;
                       }
                       
                       
                       if($this->post['hidefax'])
                       {
                       $data['hidefax']=1;
                       
                       
                       }else
                       {
                       
                       $data['hidefax']=0;
                       }
                       
                       
                       if($this->post['hideetc'])
                       {
                       $data['hideetc']=1;
                       
                       
                       }else
                       {
                       
                       $data['hideetc']=0;
                       }
                       
                       
                       if($this->post['nochecksameaddress'])
                       {
                       
                       }else
                       {
                       
                       if($data['sameaddress'])
                       {
                        
                       
                       }else
                       {
                        $data['sameaddress']=0;
                       
                       }
                       }
                       
                       if($data['email'])
                       {
                        if($data['email']==$userdata['email'])
                        {
                        unset($data['email']);
                        
                        }else if($data['email']==$userdata['emailfacebook'])
                        {
                        unset($data['email']);
                        
                        }
                        
                        else
                        {
                        $numerric=$this->checkemail($data['email']);
                        if($numerric==1)
                        {
                        
                        }else
                        {
                        $this->arraydata['error'][]=$numerric;
                        return false;
                        
                        }
                        
                        }
                       
                       
                       }else
                       {
                       
                       unset($data['email']);
                       
                       }
                       
                       
                      if($_COOKIE['timelimit'])
                            {
                            $time=$_COOKIE['timelimit'];
                            }else
                            {
                            $time=0;
                            
                            }
                             
                       if(!is_dir(imgpath.'/user/'.$userid))
                           {
                           mkdir(imgpath.'/user/'.$userid,0777);
                           chmod(imgpath.'/user/'.$userid,0777);
                           }
                       
                       if($this->post['simgmid'][0]&&$this->post['imgmid'][0])
                       {
                            $newfie=mktime().'-'.rand(0,100000).'.jpg'; 
                            $file=imgpath.'/user/'.$userid.'/'.$newfie;
                            if (!is_file($file))
                            {
                            $filelink=str_replace(baseinfo,rootpath,$this->post['filelink'][0]) ;
                            copy($filelink,$file);
                            chmod($file, 0777);
                            }                   
                              
                           $dataArray=array();
                           $dataArray['avatar']=$userid;
                           $dataArray['createby']=$userid;
                           $dataArray['updateby']=$userid;
                           $dataArray['createdate']=date("Y-m-d H:i:s");
                           $dataArray['cache']=0;
                           $dataArray['status']=1;
                           $dataArray['conid']=34;
                           
                           list($width, $height, $type, $attr) = getimagesize($file);
                           $dataArray['width']=$width;
                           $dataArray['height']=$height;
                           $dataArray['basewidth']=$width;
                           $dataArray['baseheight']=$height;
                           $dataArray['path']=str_replace(rootpath.'/','',$file);
                           $dataArray['size']=filesize($file);
                           $dataArray['imgname']=$newfie;
                           $dataArray['name']=$newfie;
                           $data['bannerimgmid']=$this->saveimagedata($dataArray);     
                            
                            $newfie=mktime().'-'.rand(0,100000).'.jpg'; 
                            $file=imgpath.'/user/'.$userid.'/'.$newfie;
                            if (!is_file($file))
                            {
                            $filelink=str_replace(baseinfo,rootpath,$this->post['filelinkcrop'][0]) ;
                            copy($filelink,$file);
                            chmod($file, 0777);
                            }
                           
                            
                       
                           $dataArray=array();
                           $dataArray['avatar']=$userid;
                           $dataArray['createby']=$userid;
                           $dataArray['updateby']=$userid;
                           $dataArray['createdate']=date("Y-m-d H:i:s");
                           $dataArray['cache']=0;
                           $dataArray['status']=1;
                           $dataArray['conid']=16;
                           list($width, $height, $type, $attr) = getimagesize($file);
                           $dataArray['width']=$width;
                           $dataArray['height']=$height;
                           $dataArray['basewidth']=$width;
                           $dataArray['baseheight']=$height;
                           $dataArray['path']=str_replace(rootpath.'/','',$file);
                           $dataArray['size']=filesize($file);
                           $dataArray['imgname']=$newfie;
                           $dataArray['name']=$newfie;
                           $data['sbannerimgmid']=$this->saveimagedata($dataArray);
                           
                           
                       
                       }
                       else
                       {
                         if($this->post['photobanner'])
                       {
                      $data['bannerimgmid']= $this->savephotobase64($this->post['photobanner']);
                      $data['sbannerimgmid']= $data['bannerimgmid'];
                       }else
                       {
                       unset($data['bannerimgmid']);
                       unset($data['sbannerimgmid']);
                       
                       }
                       
                       }
                       if($this->post['simgmid'][1]&&$this->post['imgmid'][1])
                       {    $newfie=mktime().'-'.rand(0,100000).'.jpg'; 
                            $file=imgpath.'/user/'.$userid.'/'.$newfie;
                            if (!is_file($file))
                            {
                            $filelink=str_replace(baseinfo,rootpath,$this->post['filelink'][1]) ;
                            copy($filelink,$file);
                            chmod($file, 0777);
                            }
                       
                           $dataArray=array();
                           //$dataArray['imgmid']=$this->post['imgmid'][1];
                           $dataArray['avatar']=$userid;
                           $dataArray['createby']=$userid;
                           $dataArray['updateby']=$userid;
                           $dataArray['createdate']=date("Y-m-d H:i:s");
                           $dataArray['cache']=0;
                           $dataArray['status']=1;
                           $dataArray['conid']=34;
                           list($width, $height, $type, $attr) = getimagesize($file);
                           $dataArray['path']=str_replace(rootpath.'/','',$file);
                           $dataArray['width']=$width;
                           $dataArray['height']=$height;
                           $dataArray['basewidth']=$width;
                           $dataArray['baseheight']=$height;
                           $dataArray['size']=filesize($file);
                           $dataArray['imgname']=$newfie;
                           $dataArray['name']=$newfie;
                           $data['imgmid']=$this->saveimagedata($dataArray);
                           
                             $domain='';
                      if(NameDmconnex=="Canonlife"){
                      $url='http://'.$_SERVER['HTTP_HOST'];
                      $domain='.'.get_domain($url);
                      }
                            setcookie("imguser",baseinfo.'/'.$dataArray['path'], $time, "/",$domain);
                            setcookie("width",$dataArray['width'], $time, "/",$domain);
                            setcookie("height",$dataArray['height'], $time, "/",$domain);
                            setcookie("imgmid",$data['imgmid'], $time, "/",$domain);
                           
                            $newfie=mktime().'-'.rand(0,100000).'.jpg'; 
                            $file=imgpath.'/user/'.$userid.'/'.$newfie;
                            if (!is_file($file))
                            {
                            $filelink=str_replace(baseinfo,rootpath,$this->post['filelinkcrop'][1]) ;
                            copy($filelink,$file);
                            chmod($file, 0777);
                            }
                       
                           $dataArray=array();
                           //$dataArray['imgmid']=$this->post['imgmid'][1];
                           $dataArray['avatar']=$userid;
                           $dataArray['createby']=$userid;
                           $dataArray['updateby']=$userid;
                           $dataArray['createdate']=date("Y-m-d H:i:s");
                           $dataArray['cache']=0;
                           $dataArray['status']=1;
                           $dataArray['conid']=21;
                           list($width, $height, $type, $attr) = getimagesize($file);
                           $dataArray['width']=$width;
                           $dataArray['height']=$height;
                           $dataArray['basewidth']=$width;
                           $dataArray['baseheight']=$height;
                           $dataArray['path']=str_replace(rootpath.'/','',$file);
                           $dataArray['size']=filesize($file);
                           $dataArray['imgname']=$newfie;
                           $dataArray['name']=$newfie;
                           $data['simgmid']=$this->saveimagedata($dataArray);
                           
                           $domain='';
                      if(NameDmconnex=="Canonlife"){
                      $url='http://'.$_SERVER['HTTP_HOST'];
                      $domain='.'.get_domain($url);
                      }
                            setcookie("simguser",baseinfo.'/'.$dataArray['path'], $time, "/",$domain);
                            setcookie("thumbwidth",$dataArray['width'], $time, "/",$domain);
                            setcookie("thumbheight",$dataArray['height'], $time, "/",$domain);
                            setcookie("simgmid",$data['simgmid'], $time, "/",$domain);
                           
                           
                       
                       }
                       else
                       {
                       
                       if($this->post['photomain'])
                       {
                      $data['imgmid']= $this->savephotobase64($this->post['photomain']);
                      $data['simgmid']= $data['imgmid'];
                      
                       }
                       else
                       {
                       unset($data['simgmid']);
                       unset($data['imgmid']);
                       
                       }
                       
                       
                       
                       
                       }
                       

                       
                       if($data['daybirth']&&$data['monthbirth']&&$data['yearbirth'])
                       {
                       
                       $data['birthdate']=$data['yearbirth'].'-'.sprintf('%02d',$data['monthbirth']).'-'.sprintf('%02d',$data['daybirth']);
                       
                       }
                       
                       
                       
                       
                       
                       unset($data['daybirth']);
                       unset($data['monthbirth']);
                       unset($data['yearbirth']);
                       
                       
                       if($data['dayBirthtext'])
                       {
                       
                       
                       list($day,$month,$year)=explode("/",$data['dayBirthtext']);
                       
                       $data['birthdate']=$year.'-'.sprintf('%02d',$month).'-'.sprintf('%02d',$day);
                       
                       }
                       
                       
                       unset($data['dayBirthtext']);
                       
                       //$datalog['test']=json_encode($data).' userid='.$userdata['userid'];
//                       $this->db->db_set($datalog,"tb_logtest");
                       $this->db->db_set($data,'tb_user',' userid='.$userdata['userid']);
                       $domain='';
                      if(NameDmconnex=="Canonlife"){
                      $url='http://'.$_SERVER['HTTP_HOST'];
                      $domain='.'.get_domain($url);
                      }
                       if($data['displayname'])
                       {
                       setcookie("displayname",$data['displayname'], $time, "/",$domain);
                       }
                       
                       
                       
                       if(count($this->post['modelnumber'])&&isset($this->post['modelnumber']))
                       {
                         $k=0;
                         foreach($this->post['modelnumber'] as $valuemodelnumber)
                         {
                         
                         if(trim($valuemodelnumber)!="")
                         {
                         
                         if($this->post['serialnumber'][$k])
                         {
                         $status= $this->checkserial($this->post['serialnumber'][$k]);
                          if(is_bool($status))
                          {
                          
                          $arraydata['serial']=$this->post['serialnumber'][$k];
                          $arraydata['model']=$valuemodelnumber;
                          $arraydata['createby']=$userid;
                          $arraydata['createdate']=date("Y-m-d H:i:s");
                          
                          $this->db->db_set($arraydata,'tb_serial');
                          
                          if(NameDmconnex=="Canonlife"){ 
                          
                          
                           $arraydata2=array();
                           $arraydata2['roleid']=2;
                           $this->db->db_set($arraydata2,'tb_user',' userid='.$userid);
                          
                          }
                          
                          
                          
                          }else
                          {
                          
                          $this->arraydata['error'][]=$status;
                          
                          }
                         }
                         else
                         {
                         
                         
                          $arraydata['model']=$valuemodelnumber;
                          $arraydata['createby']=$userid;
                          $arraydata['createdate']=date("Y-m-d H:i:s");
                          $this->db->db_set($arraydata,'tb_serial');
                         
                         
                         
                         }
                         
                         }
                          $k++;
                         }
                       
                       
                       
                       }
                       
                    
                       $this->get['userid']=$userdata['userid'];
                       $this->getuserdata();
                       }
                       else if($this->post['filter']==2)
                       {
                       $data=$this->post;
                       if($this->post['curpwd']&&$this->post['newpwd']&&$this->post['renewpwd'])
                       {
                       $md5password=md5($this->post['curpwd'].'-123456');
                       
                       if($md5password==$userdata['password'])
                       {
                       if($this->post['newpwd']==$this->post['renewpwd'])
                       {
                       $arraydata=array();
                       $arraydata['password']=md5($this->post['newpwd'].'-123456');
                       $this->db->db_set($arraydata,'tb_user',' userid='.$userid);
                       
                       
                       }else
                       {
                       
                       $this->arraydata['error'][]=28;
                       }
                       
                       
                       }else
                       {
                       
                       $this->arraydata['error'][]=3;
                       
                       }
                       
                       
                       
                       }else
                       {
                       
                      $this->arraydata['error'][]=4; 
                       }
                       
                       
                       }
                       else if($this->post['filter']==3)
                       {
                       $data=$this->post;
                       $arraydata['langid']=$data['langid'];
                       $arraydata['publish']=$data['publish'];
                       $arraydata['post']=$data['post'];
                       $this->db->db_set($arraydata,'tb_user',' userid='.$userid);
                       
                       }
                       else if($this->post['filter']==4)
                       {
                       
                       if($this->post['serial'])
                       {
                         $status= $this->checkserial($this->post['serial']);
                          if(is_bool($status))
                          {
                          
                          $arraydata['serial']=$this->post['serial'];
                          $arraydata['createby']=$userid;
                          $arraydata['createdate']=date("Y-m-d H:i:s");
                          
                          $this->db->db_set($arraydata,'tb_serial');
                          
                          if(NameDmconnex=="Canonlife"){ 
                          
                          
                           $arraydata2=array();
                           $arraydata2['roleid']=2;
                           $this->db->db_set($arraydata2,'tb_user',' userid='.$userid);
                          
                          }
                          
                          
                          
                          }else
                          {
                          
                          $this->arraydata['error'][]=$status;
                          
                          }
                       
                       
                       
                       }
                       
                       
                       }
                       
                       
                    }else
                    {
                    $this->arraydata['error'][]=5;
                    
                    
                    }
                    }else
                    {
                    $this->arraydata['error'][]=5;
                    $arraydata=array();
                       $arraydata['password']=md5($this->post['newpwd'].'-123456');
                       $this->db->db_set($arraydata,'tb_user',' userid='.$userid);
                    
                    }
            
            
            }
            
            
            function savesettingcanon()
            {
                  
                 //  $datalog['test']=json_encode($this->post);
//                    $this->db->db_set($datalog,"tb_logtest");
                    $userid=0;
                    if($this->userdata['oauth'])
                    {
                    $userdata=$this->getuserbyoauth($this->userdata['oauth'],',email,password,emailfacebook');
                    if($userdata['userid'])
                    {
                    
                    $userid=$userdata['userid'];
                    
                    }
                    }
                       
                       if($this->post['filter']==1)
                       {
                       
                       $data=$this->post;
                       unset($data['filelink']);
                       
                       unset($data['filelink']);
                       
                       
                       unset($data['filter']);
                       unset($data['height']);
                       unset($data['width']);
                       unset($data['fileold']);
                       unset($data['heightcrop']);
                       unset($data['widthcrop']);
                       unset($data['filelinkcrop']);
                       unset($data['photobanner']);
                       unset($data['photomain']);
                       unset($data['oauth']);
                       unset($data['infoid']);
                       unset($data['token']);
                       unset($data['qstrgt']);
                       
                       
                       
                       unset($data['serialnumber']);
                       
                       unset($data['income']);
                       unset($data['education']);
                       unset($data['like']);
                       unset($data['club']);
                       unset($data['modelother']);
                       
                       
                       unset($data['modelnumber']);
                       unset($data['modelnumber']);
                       unset($data['username_signup']);
                       unset($data['password_signup']);
                       unset($data['repassword_signup']);
                       unset($data['email_signup']);
                       
                       unset($data['username_login']);
                       unset($data['password_login']);
                       unset($data['nochecksameaddress']);
                       unset($data['recaptcha']);
                       unset($data['recaptcha_challenge_field']);
                       unset($data['recaptcha_response_field']);
                       
                       //$this->arraydata['data']=$data;
                       
                       
                       if(isset($this->post['recaptcha_response_field']))
                       {
                                       require_once(pluginpath.'/recaptcha/recaptchalib.php'); // uri
                                       $privatekey='6Lcy6ukSAAAAAFv-n9NfJmDDOTs13p6jvMWFshiX';
                                       $resp = recaptcha_check_answer ($privatekey,
                                                                $_SERVER["REMOTE_ADDR"],
                                                                $this->post["recaptcha_challenge_field"],
                                                                $this->post["recaptcha_response_field"]);
                                                                
                                                                
                                  if ($resp->is_valid) {
                                      //  echo "You got it!";
                                      
                                } else {
                                    $this->arraydata['error'][]=38;
                                    exit;
                                        # set the error code so that we can display it
                                     //   $error = $resp->error;
                                }
                                       
                                   }
                       
                       
                            
                       if($this->post['qstrgt']=='1')
                       {
                       if(count($this->post['serialnumber'])&&isset($this->post['serialnumber']))
                       {
                         $k=0;
                         foreach($this->post['serialnumber'] as $serialnumber)
                         {
                         
                         if(trim($serialnumber)!="")
                         {
                         
                      
                        // $status= $this->gotocheckcanonserial($serialnumber);
                         $status['Status']='1';
                          if($status['Status']=='1')
                          {
                          
                           if($userid)
                           {
                           
                            $sql='select serialid,createby  from tb_serial where serial="'.$serialnumber.'"';
                            $arrayserial=$this->db->db_set_1recordrow($sql);
                            if($arrayserial['serialid']&&(intval($arrayserial['createby'])!=intval($userid)))
                            {
                            $this->arraydata['error'][]=36;
                             exit;
                            
                            }
                           
                           
                           }else
                           {
                           
                           
                             $sql='select serialid,createby  from tb_serial where serial="'.$serialnumber.'"';
                            $arrayserial=$this->db->db_set_1recordrow($sql);
                            if($arrayserial['serialid'])
                            {
                            $this->arraydata['error'][]=36;
                             exit;
                            
                            }
                           
                           
                           }
                          
                      //   $arraydata=array();
//                         $arraydata['serial']=$serialnumber;
//                         $arraydata['model']=$status['ModelName'];
//                         $arraydata['description']=$status['Description'];
//                         $arraydata['productcategory']=$status['Product_Category'];
//                         $arraydata['productdivision']=$status['Product_Division'];
//                         $arraydata['stockcode']=$status['StockCode'];
//                         $arraydata['warrantynumber']=$status['WarrantyNumber'];
//                         $arraydata['createby']=$userid;
//                         $arraydata['createdate']=date("Y-m-d H:i:s");
//                         $this->db->db_set($arraydata,'tb_serial');
                         
//                          $arraydata['model']=$valuemodelnumber;
//                          $arraydata['createby']=$userid;
//                          $arraydata['createdate']=date("Y-m-d H:i:s");
//                          
//                          $this->db->db_set($arraydata,'tb_serial');
                          
                          if(NameDmconnex=="Canonlife"){ 
                          
                          
                       //    $arraydata2=array();
//                           $arraydata2['roleid']=2;
//                           $this->db->db_set($arraydata2,'tb_user',' userid='.$userid);
                          
                          }
                          
                          
                          
                          }else
                          {
                          
                          $this->arraydata['error'][]=35;
                          exit;
                          
                          }
                      
                     
                         
                         }
                          
                         }
                       
                       
                       
                       }
                       }
                       
                       if($userid==0)
                       {
                       $email=$this->post['email'];
                       $check2=$this->checkemail($email);
          
                       if($check2==1)
                       {
                       list($username,$p)=explode("@",$email);
                       
                       
                       $userArray['username']=$username.'-'.mktime();
                       $userArray['displayname']=$username;
                       $userArray['email']=$email;
                       $password=substr(md5($username.(mktime()+rand(0,100000))),0,8);
                       $md5password=md5($password.'-123456');
                       $userArray['password']=$md5password;
                       $userArray['oauth']=md5(mktime().$md5password);
                       $userArray['status']=1;
                       
                       //$userArray['passwordset']=$password;
                       
                       
                       
                       
                       $userid=$this->saveregister($userArray,1);
          // $this->savescoredata($userid,2);
                      //  $this->savegamenictaionbygxcid($userid,2);
                       
                       $userArray['userid']=$userid;
                       $this->arraydata['data']=$userArray;
                       $this->post['oauth']=$userArray['oauth'];
                    //   exit;
                        $this->login();

                       require_once(pluginpath.'/phpmailer/class.config.php'); // uri
           
                        $mail = new ConfigMail();
           //$mail->setFrom("s_chanyut@hotmail.com","Bird Kung");
                       $mail->setTo($email,$username);
                       $mail->setContent(' Username:'.$userArray['username'].'<br>Password:'.$password);
                       $mail->setSubject("Welcome To  ".NameDmconnex);
                       $mail->sendTo();
                       
                       
                       }else
                       {
                       
                       
                       
                       $this->arraydata['error'][]=$check2;
                       exit;
                       }
                       }
                       
                       
                       
                    //   exit;
                       
                       
                       
                   //    unset($data['dayBirthtext']);
                       
                
                   
                       
                       unset($data['email']);
                       
                       
                       
                       
                      if($_COOKIE['timelimit'])
                            {
                            $time=$_COOKIE['timelimit'];
                            }else
                            {
                            $time=0;
                            
                            }
                             
                       if(!is_dir(imgpath.'/user/'.$userid))
                           {
                           mkdir(imgpath.'/user/'.$userid,0777);
                           chmod(imgpath.'/user/'.$userid,0777);
                           }
                       
                      

                       
                       if($data['daybirth']&&$data['monthbirth']&&$data['yearbirth'])
                       {
                       
                       $data['birthdate']=$data['yearbirth'].'-'.sprintf('%02d',$data['monthbirth']).'-'.sprintf('%02d',$data['daybirth']);
                       
                       }
                       
                       
                       
                       
                       
                       unset($data['daybirth']);
                       unset($data['monthbirth']);
                       unset($data['yearbirth']);
                       
                       
                       if($data['dayBirthtext'])
                       {
                       
                       
                       list($day,$month,$year)=explode("/",$data['dayBirthtext']);
                       
                       $data['birthdate']=$year.'-'.sprintf('%02d',$month).'-'.sprintf('%02d',$day);
                       
                       }
                       
                       
                       unset($data['dayBirthtext']);
                       
                       //$datalog['test']=json_encode($data).' userid='.$userdata['userid'];
//                       $this->db->db_set($datalog,"tb_logtest");
                       $this->db->db_set($data,'tb_user',' userid='.$userid);
                       $domain='';
                      if(NameDmconnex=="Canonlife"){
                      $url='http://'.$_SERVER['HTTP_HOST'];
                      $domain='.'.get_domain($url);
                      }
                       if($data['displayname'])
                       {
                       setcookie("displayname",$data['displayname'], $time, "/",$domain);
                       }
                       
                       
                       $arrayother=array();
                       $arrayother['education']=$this->post['education'];
                       $arrayother['income']=$this->post['income'];
                       $arrayother['club']=$this->post['club'];
                       $arrayother['like']=$this->post['like'];
                       $arrayother['userid']=$userid;
                       $arrayother['userid']=$userid;
                       $arrayother['iscanon']=$this->post['qstrgt'];
                       if($this->post['qstrgt']=='2')
                       {
                       $arrayother['model']=$this->post['modelother'];
                       }
                       
                       $arrayother['updatedate']=date("Y-m-d H:i:s");
                       $sql='select * from tb_user_other where userid='.$userid;
                       
                       $userother=$this->db->db_set_1recordrow($sql);
                       
                       if($userother['userid'])
                       {
                       
                       $this->db->db_set($arrayother,'tb_user_other',' userid='.$userother['userid']);
                       
                       }else
                       {
                       
                       $arrayother['createdate']=date("Y-m-d H:i:s");
                       $this->db->db_set($arrayother,'tb_user_other');
                       
                       }
                       
                                             
                       if($this->post['qstrgt']=='1')
                       {
                       
                       if(count($this->post['serialnumber'])&&isset($this->post['serialnumber']))
                       {
                         $k=0;
                         foreach($this->post['serialnumber'] as $serialnumber)
                         {
                         
                         if(trim($serialnumber)!="")
                         {
                         
                      
                        // $status= $this->gotocheckcanonserial($serialnumber);
                         $status['Status']='1';
                          if($status['Status']=='1')
                          {
                          
                           if($userid)
                           {
                           
                            $sql='select serialid,createby  from tb_serial where serial="'.$serialnumber.'"';
                            $arrayserial=$this->db->db_set_1recordrow($sql);
                           if($arrayserial['serialid']&&(intval($arrayserial['createby'])==intval($userid)))
                            {
                          $arraydata=array();
                         $arraydata['serial']=$serialnumber;
                         $arraydata['model']=$this->post['modelnumber'][$k];
                         $arraydata['description']=$status['Description'];
                         $arraydata['productcategory']=$status['Product_Category'];
                         $arraydata['productdivision']=$status['Product_Division'];
                         $arraydata['stockcode']=$status['StockCode'];
                         $arraydata['warrantynumber']=$status['WarrantyNumber'];
                         
                         
                         $this->db->db_set($arraydata,'tb_serial',' createby='.$userid);
                            
                            
                            }
                            else
                            {
                            
                         $arraydata=array();
                         $arraydata['serial']=$serialnumber;
                         $arraydata['model']=$this->post['modelnumber'][$k];
                         $arraydata['description']=$status['Description'];
                         $arraydata['productcategory']=$status['Product_Category'];
                         $arraydata['productdivision']=$status['Product_Division'];
                         $arraydata['stockcode']=$status['StockCode'];
                         $arraydata['warrantynumber']=$status['WarrantyNumber'];
                         $arraydata['createby']=$userid;
                         $arraydata['createdate']=date("Y-m-d H:i:s");
                         $this->db->db_set($arraydata,'tb_serial');
                         
                          
                            
                            
                            }
                            $k++;
                            if(NameDmconnex=="Canonlife"){ 
                          
                          
                       //    $arraydata2=array();
//                           $arraydata2['roleid']=2;
//                           $this->db->db_set($arraydata2,'tb_user',' userid='.$userid);
                          
                          }
                           
                           }
                          
                      //   $arraydata=array();
//                         $arraydata['serial']=$serialnumber;
//                         $arraydata['model']=$status['ModelName'];
//                         $arraydata['description']=$status['Description'];
//                         $arraydata['productcategory']=$status['Product_Category'];
//                         $arraydata['productdivision']=$status['Product_Division'];
//                         $arraydata['stockcode']=$status['StockCode'];
//                         $arraydata['warrantynumber']=$status['WarrantyNumber'];
//                         $arraydata['createby']=$userid;
//                         $arraydata['createdate']=date("Y-m-d H:i:s");
//                         $this->db->db_set($arraydata,'tb_serial');
                         
//                          $arraydata['model']=$valuemodelnumber;
//                          $arraydata['createby']=$userid;
//                          $arraydata['createdate']=date("Y-m-d H:i:s");
//                          
//                          $this->db->db_set($arraydata,'tb_serial');
                          
                         
                          
                          
                          
                          }else
                          {
                          
                          $this->arraydata['error'][]=35;
                          exit;
                          
                          }
                      
                     
                         
                         }
                          
                         }
                       
                       
                       
                       }
                       }
                      
                       
                       
                    
                       $this->get['userid']=$userid;
                       $this->getuserdata();
                       }
                  
                       
                    
                   
            
            
            }
            
            
            
            function getmynotificationlist()
            {
            
            if($this->post['page'])
            {
            if($this->userdata['oauth'])
            {
            $userdata=$this->getuserbyoauth($this->userdata['oauth']);
            if($userdata['userid'])
            {
            
             $this->arraydata['data']=$this->getnotificationlistbyuserid($userdata['userid'],$this->post['page'],$this->post['filter'],$this->post['nottid'],$this->post['dateset']);
            
            
            
            }
            }
            else
            {
            $this->arraydata['data']=$this->getnotificationlistbyuserid('',$this->post['page'],$this->post['filter']);     
            
            }
            
            
            }
            
            }
            
            function readnotification()
            {
            if($this->userdata['oauth']&&$this->post['notiid'])
            {
            $arrayuser=$this->getuserbyoauth($this->userdata['oauth']);
            if($arrayuser['userid'])
            {
            $sql="select notiid,tb_notification.read,notifyid from tb_notification where notiid=".$this->post['notiid'];
            $notificationbox=$this->db->db_set_1recordrow($sql);
            if($notificationbox['notifyid']!=0)
            {

            if($this->checkreadnotify($arrayuser['userid'],$notificationbox['notifyid'])===false)
            {
            
               $arraydata['notifyid']=$notificationbox['notifyid'];
               $arraydata['userid']=$arrayuser['userid'];
               $arraydata['status']=1;
               $arraydata['createdate']=date("Y-m-d H:i:s");
               $this->db->db_set($arraydata,'tb_read_notify');
               
               
               $sql="select badge from tb_user where userid=".$arrayuser['userid'];
               $userdata=$this->db->db_set_1recordrow($sql);
               if($userdata['badge'])
               {
                $userdata['badge']=$userdata['badge']-1;
                $this->db->db_set($userdata,'tb_user',' userid='.$arrayuser['userid']);
                
               }
               
            
            }
            
            
            }
            else if($notificationbox['read']==0)
            {
            
              $arraydata['read']=1;
              $this->db->db_set($arraydata,'tb_notification',' notiid='.$this->post['notiid']);
              
              $sql="select badge from tb_user where userid=".$arrayuser['userid'];
               $userdata=$this->db->db_set_1recordrow($sql);
              if($userdata['badge'])
               {
                $userdata['badge']=$userdata['badge']-1;
                $this->db->db_set($userdata,'tb_user',' userid='.$arrayuser['userid']);
                
               }
            
            
            }
            
            
            }
            
            }
            
            
            
            }
            
            function exitreaddata()
            {
            $array=exif_read_data(rootpath.'/images/liberty-canon.jpg', 0, true);
            echo "<pre>";
            print_r($array);
            echo "</pre>;";
            
            }
            
            function countnotification()
            {
            if($this->userdata['oauth'])
            {
            $userdata=$this->getuserbyoauth($this->userdata['oauth']);
            if($userdata['userid'])
            {
            
            // $countdata1=$this->countnotificationlistbyuserid($userdata['userid'],0,0);
             //$countdata2=$this->countnotificationlistbyuserid($userdata['userid'],3,0);
             
             
          //   $arraydata['badge']=0;
           //  $this->db->db_set($arraydata,'tb_user',' userid='.$arrayuser['userid']);
             $sql="select badge from tb_user where userid=".$userdata['userid'];
             $data=$this->db->db_set_1recordrow($sql);
             
             $this->arraydata['data']['countdata']=intval($data['badge']);
            
            
            
            }
            }
            
            }
            
            function saveconfirmcode()
            {
            
            $data['refcode']=$this->get['refcode'];
            $data['status']=$this->get['status'];
            $data['reason']=$this->get['reason'];
            $sql="select refcode from tb_refer_status where refcode='".$data['refcode']."'";
            $arraydata=$this->db->db_set_1recordrow($sql);
            if($arraydata['refcode'])
            {
            $this->db->db_set($data,'tb_refer_status',' refcode="'.$arraydata['refcode'].'"');
            }else
            {
            $this->db->db_set($data,'tb_refer_status');
            
            }
            
            
            
            
            }
            function genservicerefcode()
            {
              if($this->userdata['userid'])
              {
              $refcode=$this->genrefcode();
              $arraydata['refcode']=$refcode;
              $arraydata['createby']=$this->userdata['userid'];
              $arraydata['createdate']=date("Y-m-d H:i:s");
              $this->db->db_set($arraydata,'tb_refer');
              $arraydataset['refcode']=$refcode;
              $arraydataset['user']=$this->getuseralldata($this->userdata['oauth']);
              $this->arraydata['data']=$arraydataset;
              }else
            {
            $this->arraydata['error'][]=5;
            
            }
            
            }
            
            function getallpremiumuser()
            {
            $sql='SELECT
tb_banner_public.simgmid,
tb_banner_public.pname as displayname,
tb_banner_public.pemail as emaicontact,
tb_user.userid
FROM
tb_user
INNER JOIN tb_banner_public ON tb_user.userid = tb_banner_public.createby
             where tb_user.roleid=2';
             $arraydata=$this->db->db_set_recordset($sql);
             $k=0;
             if(count($arraydata))
             {
             foreach($arraydata as $valuedata)
             {
             $imgpath=$this->getimagebyimgmid($valuedata['simgmid']);
             $arraydata[$k]['imgpath']=$imgpath['newpath'];
             $k++;
             }
             
             }
            $this->arraydata['data']=$arraydata;
            }
            
            function getuserdata()
            {
              if($this->get['userid'])
              {
              $sql="select userid,oauth,publish from tb_user where tb_user.userid='".$this->get['userid']."'";
              $arrayuser=$this->db->db_set_1recordrow($sql);
              if($arrayuser['userid'])
              {

              
              if(($this->userdata['oauth']!=$arrayuser['oauth'])&&$arrayuser['publish']==0)
              {
               
               if($this->userdata['oauth'])
               {
               $checkfollow=$this->checkuserfollow($arrayuser['userid'],$this->userdata['oauth']);
               
               if($checkfollow)
               {
               $checkallow=true;
               
               }else
               {
               
               $checkallow=false;
               }
               
               
               }else
               {
               $checkfollow=false;
               $checkallow=false;
               }
               
               
               
              }
              else if($this->userdata['oauth']!=$arrayuser['oauth']&&$arrayuser['publish']==1)
              {
              $checkfollow=$this->checkuserfollow($arrayuser['userid'],$this->userdata['oauth']);
               //$checkfollow=true;
               $checkallow=true;
                            
              }else
              {
              $checkfollow=true;
              $checkallow=true;
              
              }
              
              
              $arraynewdata=array();           
              $arraynewdata=$this->memcache->get($arrayuser['oauth']);
               if(count($arraynewdata)==0||$_GET['nocahce']==1)
               {
              $arraynewdata=$this->getuseralldata($arrayuser['oauth']);
              $this->memcache->set($arrayuser['oauth'],$arraynewdata);
              }
              $arraynewdata['userdata']['checkfollow']=$checkfollow;
              $this->arraydata['data']=$arraynewdata['userdata'];
              
              
              
             
              
              }else
              {
              
              $this->arraydata['error'][]=5;
              
              }
              
              }else
              {
              $this->arraydata['error'][]=5;
              
              }
            
            
            
            }
            
            function sendmsg()
            {
            if(($this->userdata['oauth']&&$this->post['userid'])&&($this->post['msg']||$this->post['imgmid']||$this->post['imgdata']))
             {
             
             $arrayuser=$this->getuserbyoauth($this->userdata['oauth']);
             if($arrayuser['userid'])
             {
             $msglid=$this->getmsglistid($this->post['userid'],$this->userdata['oauth']);
             if(is_numeric($msglid))
             {
             $arraydata=array();
             $arraydata['msglid']=$msglid;
             $arraydata['userid']=$this->post['userid'];
             $arraydata['createby']=$arrayuser['userid'];
             $arraydata['createdate']=date("Y-m-d H:i:s");
             if($this->post['msg'])
             {
             $arraydata['msg']=$this->post['msg'];
             $msgto=$arrayuser['displayname'].' '.$this->getconditionmsgbyid(2).'  '.$arraydata['msg'];
             }
             
             if($this->post['imgmid'])
             {
             $arraydata['imgmid']=$this->post['imgmid'];
             $msgto=$arrayuser['displayname'].' '.$this->getconditionmsgbyid(36);
             }
             
             if($this->post['imgdata'])
             {
             $arraydata['imgmid']=$this->saveimagebase64($this->post['imgdata'],$this->userdata['oauth']);
             $msgto=$arrayuser['displayname'].' '.$this->getconditionmsgbyid(36);
             }
             
             $this->db->db_set($arraydata,"tb_msg");
             $msgid=$this->db->db_get_last_number();
             
             $sql='SELECT msgid FROM `tb_msg` where  (createby='.$arrayuser['userid'].' and userid='.$this->post['userid'].')';
             $arraycheckmsg=$this->db->db_set_1recordrow($sql);
             if($arraycheckmsg['msgid'])
             {
             
             }else
             {
             $this->savegamenictaionbygxcid($arrayuser['userid'],8);
             
             }
             
             
             
             $arraydataset=array();
             $arraydataset['msgid']=$msgid;
             $arraydataset['userid']=$arrayuser['userid'];
             $arraydataset['createby']=$this->post['userid'];
             $arraydataset['conid']=35;
             $arraydataset['read']=1;
             
             $this->savenotificationlist($arraydataset);
             $arraydataset['userid']=$this->post['userid'];
             $arraydataset['createby']=$arrayuser['userid'];
             $arraydataset['conid']=2;
             $arraydataset['read']=0;
             
             $notiid[$arraydataset['userid']]=$this->savenotificationlist($arraydataset);
             $userids=array();
             $userids[]=$arraydataset['userid'];
             $this->sendtonotification($userids,$msgto,$notiid);
             
             
             }else
             {
             $this->arraydata['error'][]=27;
             
             }
             }else
             {
             $this->arraydata['error'][]=5;
             
             }
             
             }else
             {
             $this->arraydata['error'][]=4;
             
             }
            
            
            }
            
            function getmsglist()
            {
            if(($this->userdata['oauth']&&$this->post['userid']&&$this->post['page']))
            {
            
            $this->arraydata['data']=$this->getallmsglist($this->post['userid'],$this->userdata['oauth'],$this->post['page']);
            
            
            }
            
            }
            
            
            function followuser()
            {

             if($this->userdata['oauth']&&$this->post['userid'])
             {
              $boolean=$this->followuserfunction($this->post['userid'],$this->userdata['oauth']);  
               if($boolean)
              {
               if($this->post['userdatasetfollowcheck'])
               {
               $this->arraydata['data']['countfollow']=$this->countfollower($this->post['userdatasetfollowcheck']);
               $this->arraydata['data']['countfollowing']=$this->countfollowing($this->post['userdatasetfollowcheck']);
               }else
               {
               $this->arraydata['data']['countfollow']=$this->countfollower($this->post['userid']);
               $this->arraydata['data']['countfollowing']=$this->countfollowing($this->post['userid']);
               
               }
               
               
               
               
               $this->arraydata['data']['checkfollow']=$this->checkuserfollow($this->post['userid'],$this->userdata['oauth']);


               if($this->arraydata['data']['checkfollow']===4||$this->arraydata['data']['checkfollow']===5)
               {
               
                $this->arraydata['error'][]=26; 
               
               }
              
              }else
              {
              $this->arraydata['error'][]=25;   
              
              }
             
             
             }else
             {
             $this->arraydata['error'][]=5;   
             }
            
            }
            
            function blockuser()
            {
                
                if($this->userdata['oauth']&&$this->post['userid']&&$this->post['status'])
                {
              $boolean=$this->blockuserfunction($this->post['userid'],$this->userdata['oauth'],$this->post['status']);  
               if($boolean)
              {
               $this->arraydata['data']['countblock']=$this->countblock($this->post['userid']);
               }else
              {
              $this->arraydata['error'][]=25;   
              
              }
             
             
             }else
             {
             $this->arraydata['error'][]=5;   
             }
             
            }
            
            function acceptuser()
            {
            if($this->userdata['oauth']&&$this->post['userid'])
             {
              $boolean=$this->acceptuserfunction($this->post['userid'],$this->userdata['oauth']);  
               if($boolean)
              {
               $this->arraydata['data']['countrequest']=$this->countrequests($this->post['userid']);



               
              
              }else
              {
              $this->arraydata['error'][]=25;   
              
              }
             
             
             }else
             {
             $this->arraydata['error'][]=5;   
             }
            
            }
            
            function requestuserlist()
            {
              if($this->userdata['oauth']&&$this->post['page'])
              {
                
              $this->arraydata['data']=$this->getlistuserbystatus($this->userdata['userid'],3,$this->post['page']);
              
              }else
              {
              $this->arraydata['error'][]=5; 
              
              }
            
            
            
            }
            
            function followeruserlist()
            {
              if($this->post['userid']&&$this->post['page'])
              {
                
              $this->arraydata['data']=$this->getlistuserbystatus($this->post['userid'],1,$this->post['page']);
              
              }else
              {
              $this->arraydata['error'][]=5; 
              
              }
            
            
            
            }
            
            function followinguserlist()
            {
              if($this->post['userid']&&$this->post['page'])
              {
                
              $this->arraydata['data']=$this->getlistuserbystatus($this->post['userid'],2,$this->post['page']);
              
              }else
              {
              $this->arraydata['error'][]=5; 
              
              }
            
            
            
            }
            
            function suggestionfriendlist()
            {
            
                 if($this->post['userid']&&$this->post['page'])
                  {
                
                    $this->arraydata['data']=$this->getlistuserbystatus($this->post['userid'],7,$this->post['page'],$this->post['search']);
              
                  }else
                  {
                  $this->arraydata['error'][]=5; 
                  
                  }
            
            
            }
            
            function getuserlistbystatus()
            {
            
             if($this->post['userid']&&$this->post['page']&&$this->post['status'])
              {
                
              $this->arraydata['data']=$this->getlistuserbystatus($this->post['userid'],$this->post['status'],$this->post['page'],$this->post['search']);
              
              }else
              {
              $this->arraydata['error'][]=5; 
              
              }
            
            }
            
            
            function getfacebookuserlistbystatus()
            {
              if($this->userdata['oauth'])
              {
              $txtsearch='';
              if($this->post['searchfTxtSugg'])
              {
              $txtsearch=$this->post['searchfTxtSugg'];
              }
              
              
             require pluginpath.'/facebook/facebook.php';
           //  $array1=array(array('name'=>'Sirichol Ruangsri','id'=>521252855),array('name'=>'Pimporn Phupha','id'=>522927880));
//             $array2=array(array('name'=>'นุกกี้ ลูกหมีป่า สามสิบเจ็ดหาง','id'=>523716272),array('name'=>'Piyawut Chaiphak','id'=>538072822));
//             
//             $array3=array_merge($array1,$array2);
//             
//             $array4=array(array('name'=>'นุกกี้ ลูกหมีป่า สามสิบเจ็ดหาง','id'=>523716272),array('name'=>'Piyawut Chaiphak','id'=>538072822));
//             
//             $array5=array_merge($array3,$array4);
//             echo "<pre>";
//             print_r($array5);
//             echo "</pre>;";
//             
//             exit;
            
            $facebook = new Facebook(array(
            'appId'  =>facebookappid,
            'secret' =>facebooksecret,
            ));
            
            
            $user = $facebook->getUser();

            
            if ($user) {
           
            $arrayfriend=array();
             $i=0;
             $k=0;
             while($i<1)
             {
             
             $friendslist = $facebook->api('/me/friends?limit=500&offset='.$k);
             
             $k=$k+500;
             if(count($friendslist['data']))
             {
             if(count($arrayfriend))
             {
             $arrayfriend=array_merge($arrayfriend,$friendslist['data']);
             
             }else
             {
             $arrayfriend=$friendslist['data'];
             
             }
             
             
             
             
             
             }else
             {
             break;
             
             }
             
             if($k>1000)
             {
             $i=100;
             break;
             }
             
             }
             

             $arraynewdata=array();
             
            $arrayids=array();
            if(count($arrayfriend))
            {
            foreach($arrayfriend as $valuefriends)
            {
            $arrayids[]=$valuefriends['id'];
            
            
            }
            $strids='"'.join('","',$arrayids).'"';
            $sql='select facebookid,username,displayname,userid,imgmid,simgmid from tb_user where tb_user.facebookid IN ('.$strids.')';

            $arrayhasf=$this->db->db_set_recordset($sql);
            
            $arraycheckf=array();
            
            if(count($arrayhasf))
            {
            foreach($arrayhasf as $valuehasf)
            {
            
            

            $arraycheckf[]=$valuehasf['facebookid'];
            $arname=array();
            $arname['username']=$valuehasf['username'];
            $arname['displayname']=$valuehasf['displayname'];
            $arname['oauth']='';
            $arname['imgmid']=$valuehasf['imgmid'];
            $arname['simgmid']=$valuehasf['simgmid'];
            $arname['userid']=$valuehasf['userid'];
            
            $arname['checkfollow']=$this->checkuserfollow($valuehasf['userid'],$this->userdata['oauth']);
            $arname['imgarray']=$this->getimagebyimgmid($valuehasf['imgmid']);
            $arname['simgarray']=$this->getimagebyimgmid($valuehasf['simgmid']);
            
            if($txtsearch)
            {
            if(strpos($arname['displayname'],$txtsearch)!==false)
            {
            
            $arraynewdata[]=$arname;
            
            }else if(strpos($arname['username'],$txtsearch)!==false)
            {
            
            $arraynewdata[]=$arname;
            }
            
            }else
            {
            $arraynewdata[]=$arname;
            }
            
            
            
            }
            
            }
            
            foreach($arrayfriend as $valuefriends)
            {
            if(array_search($valuefriends['id'],$arraycheckf)===false)
            {
            
            
            
            $arname=array();
            $arname['username']=$valuefriends['name'];
            $arname['displayname']=$valuefriends['name'];
            $arname['oauth']='';
            $arname['imgmid']=0;
            $arname['simgmid']=0;
            $arname['userid']=0;
            $arname['facebookid']=$valuefriends['id'];
            
            $arname['checkfollow']=false;
           // $arname['imgarray']=array('newpath'=>);
            $arname['simgarray']=$this->getimagebyimgmid($valuehasf['simgmid']);
            $arname['simgarray']['newpath']='https://graph.facebook.com/'.$valuefriends['id'].'/picture?type=square';
            if($txtsearch)
            {
            if(strpos($arname['displayname'],$txtsearch)!==false)
            {
            
            $arraynewdata[]=$arname;
            
            }
            
            }else
            {
            $arraynewdata[]=$arname;
            }
            
            }
            
            }
            
            
            }
            
            
            $this->arraydata['data']=$arraynewdata;
            
            
                     //   exit;
            
            }else
            {
            $this->arraydata['data']=array();
            
            }
            
            

            
          
            

              
              
                
             // $this->arraydata['data']=$this->getlistuserbystatus($this->post['userid'],$this->post['status'],$this->post['page'],$this->post['search']);
              
              }else
              {
              $this->arraydata['error'][]=5; 
              
              }
            
            }
            
            
            function blockuserlist()
            {
              if($this->userdata['oauth']&&$this->post['page'])
              {
                
              $this->arraydata['data']=$this->getlistuserbystatus($this->userdata['oauth'],4,$this->post['page']);
              
              }else
              {
              $this->arraydata['error'][]=5; 
              
              }
            
            
            
            }
            
            function sendboardcasting()
            {
            
            if($this->post['msg']&&$this->userdata['oauth'])
            {
            
             if($this->saveboardcasting($this->post['msg'],$this->userdata['oauth']))
             {
             
             
             
             }else
             {
             
             $this->arraydata['error'][]=11;
             
             }
            
            
            
            
            }
            
            
            }
            
            function sendnotify()
            {
             if($this->post['msg']&&$this->userdata['oauth'])
            {
            
             if($this->savenotify($this->post['msg'],$this->userdata['oauth']))
             {
             
             
             
             }else
             {
             
             $this->arraydata['error'][]=11;
             
             }
            
            
            
            
            }
            
            }
            function getalltag()
            {
            
            
            
            }
            
            
            function getallfeature()
            {
             if(count($this->info['configall']['feature']))
             {
             $row=0;
             foreach($this->info['configall']['feature'] as $valuefeature)
             {
             

             if($valuefeature['bannermain']&&count($valuefeature['bannermain']))
             {
             foreach($valuefeature['bannermain'] as $keyset=> $valuebannerset)
             {
             if(is_array($valuebannerset))
             {
             $krow=0;
             foreach($valuebannerset as $valuebannerset2)
             {
             
          if(is_file(rootpath.'/assets/banner/'.$valuebannerset2['img'])&&$valuebannerset2['img'])
             {
             $valuebannerset[$krow]['banner']=baseinfo.'/assets/banner/'.$valuebannerset2['img'];
             list($width, $height, $type, $attr) =getimagesize(rootpath.'/assets/banner/'.$valuebannerset2['img']);
             $valuebannerset[$krow]['ratio']=@($width/$height);
             
             }else
             {
             unset($valuebannerset[$krow]);
             
             }
             
             $krow++;
             }
             
             $valuefeature['bannermain'][$keyset]=$valuebannerset;
             }
             
             
             
             }
             
             if($valuefeature['bannermain']['ipad'])
             {
             
             }else
             {
             $valuefeature['bannermain']['ipad']=array();
             }
             
             
             if($valuefeature['bannermain']['iphone'])
             {
             
             }else
             {
             $valuefeature['bannermain']['iphone']=array();
             }
             
             
             }
             else
             {
             
             $valuefeature['bannermain']['ipad']=array();
             $valuefeature['bannermain']['iphone']=array();
             
             }
             
             $this->info['configall']['feature'][$row]['bannermain']=$valuefeature['bannermain'];
             
             
             
             if($valuefeature['bannerlanding']&&count($valuefeature['bannerlanding']))
             {
             foreach($valuefeature['bannerlanding'] as $keyset=> $valuebannerset)
             {
             if(is_array($valuebannerset))
             {
             $krow=0;
             foreach($valuebannerset as $valuebannerset2)
             {
             
          if(is_file(rootpath.'/assets/banner/'.$valuebannerset2['img'])&&$valuebannerset2['img'])
             {
             $valuebannerset[$krow]['banner']=baseinfo.'/assets/banner/'.$valuebannerset2['img'];
             list($width, $height, $type, $attr) =getimagesize(rootpath.'/assets/banner/'.$valuebannerset2['img']);
             $valuebannerset[$krow]['ratio']=@($width/$height);
             
             }else
             {
             unset($valuebannerset[$krow]);
             
             }
             
             $krow++;
             }
             
             $valuefeature['bannerlanding'][$keyset]=$valuebannerset;
             }
             
             
             
             
             
             }
             
                if($valuefeature['bannerlanding']['ipad'])
             {
             
             }else
             {
             $valuefeature['bannerlanding']['ipad']=array();
             }
             
             
             if($valuefeature['bannerlanding']['iphone'])
             {
             
             }else
             {
             $valuefeature['bannerlanding']['iphone']=array();
             }
             
             
             } else
             {
             
             $valuefeature['bannerlanding']['ipad']=array();
             $valuefeature['bannerlanding']['iphone']=array();
             
             }
             
             
             $this->info['configall']['feature'][$row]['bannerlanding']=$valuefeature['bannerlanding'];
             
            // exit;
             

             
             
               $this->info['configall']['feature'][$row]['tagsystem']=$this->gettagbyfid($valuefeature['fid'],1,1);
               $this->info['configall']['feature'][$row]['taguser']=$this->gettagpoppular($valuefeature['fid']);
               
               $row++;
             
             
             }
             
             
             
             }
             $krow=0;
             $arraydatafeature=array();
             if(count($this->info['configall']['feature']))
             {
             foreach($this->info['configall']['feature'] as $valuefeature)
             {
             if($valuefeature['istag']==1)
             {
             
            // unset($this->info['configall']['feature'][$krow]);
             
             }
             else if($valuefeature['isiframe']==1)
             {
             
             
             }
             else
             {
             
             $arraydatafeature[]=$valuefeature;
             
             }
             
             $krow++;
             }
             }
             
             
              
             $this->arraydata['data']=$arraydatafeature;
            
            }
            
            function getallfeaturetest()
            {
             if(count($this->info['configall']['feature']))
             {
             $row=0;
             foreach($this->info['configall']['feature'] as $valuefeature)
             {
             

             

             if($valuefeature['bannermain']&&count($valuefeature['bannermain']))
             {

             foreach($valuefeature['bannermain'] as $keyset=> $valuebannerset)
             {
             if(is_array($valuebannerset))
             {
             $krow=0;
             foreach($valuebannerset as $valuebannerset2)
             {
             
          if(is_file(rootpath.'/assets/banner/'.$valuebannerset2['img'])&&$valuebannerset2['img'])
             {
             $valuebannerset[$krow]['banner']=baseinfo.'/assets/banner/'.$valuebannerset2['img'];
             list($width, $height, $type, $attr) =getimagesize(rootpath.'/assets/banner/'.$valuebannerset2['img']);
             $valuebannerset[$krow]['ratio']=@($width/$height);
             
             }else
             {
             unset($valuebannerset[$krow]);
             
             }
             
             $krow++;
             }
             
             $valuefeature['bannermain'][$keyset]=$valuebannerset;
             }
             
             
             
             }
             $this->info['configall']['feature'][$row]['bannermain']=$valuefeature['bannermain'];
             }
             
             
             
             if($valuefeature['bannerlanding']&&count($valuefeature['bannerlanding']))
             {
             foreach($valuefeature['bannerlanding'] as $keyset=> $valuebannerset)
             {
             if(is_array($valuebannerset))
             {
             $krow=0;
             foreach($valuebannerset as $valuebannerset2)
             {
             
          if(is_file(rootpath.'/assets/banner/'.$valuebannerset2['img'])&&$valuebannerset2['img'])
             {
             $valuebannerset[$krow]['banner']=baseinfo.'/assets/banner/'.$valuebannerset2['img'];
             list($width, $height, $type, $attr) =getimagesize(rootpath.'/assets/banner/'.$valuebannerset2['img']);
             $valuebannerset[$krow]['ratio']=@($width/$height);
             
             }else
             {
             unset($valuebannerset[$krow]);
             
             }
             
             $krow++;
             }
             
             $valuefeature['bannerlanding'][$keyset]=$valuebannerset;
             }
             
             
             
             }
             $this->info['configall']['feature'][$row]['bannerlanding']=$valuefeature['bannerlanding'];
             }
             
            // exit;
             

             
             
               $this->info['configall']['feature'][$row]['tagsystem']=$this->gettagbyfid($valuefeature['fid'],1,1);
               $this->info['configall']['feature'][$row]['taguser']=$this->gettagpoppular($valuefeature['fid']);
               
               $row++;
             
             
             }
             
             }
             $krow=0;
             if(count($this->info['configall']['feature']))
             {
             foreach($this->info['configall']['feature'] as $valuefeature)
             {
             if($valuefeature['istag']==1)
             {
             echo "test";
             unset($this->info['configall']['feature'][$krow]);
             
             }
             
             $krow++;
             }
             }
              
             $this->arraydata['data']=$this->info['configall']['feature'];
            
            }
            
            function getallbanner()
            {
            if($this->get['userid'])
            {
            $sql='SELECT * FROM `tb_banner_user` where  `tb_banner_user`.createby='.$this->get['userid'].' order by sort asc';
            $arraydata=$this->db->db_set_recordset($sql);
            if(count($arraydata))
            {
            $k=0;
            foreach($arraydata as $valuedata)
            {
            $arrimg=$this->getimagebyimgmid($valuedata['simgmid']);
            $this->arraydata['data'][$k]['banner']=$arrimg['newpath'];
            if($valuedata['status']=='1')
            {
            $this->arraydata['data'][$k]['link']=$valuedata['link'];
            $this->arraydata['data'][$k]['tag']='';
            
            list($urinow,$urinow2)=explode("?",$valuedata['link']);
            if(strpos($urinow,baseinfo)!==false)
            {
            
            
            
            $arrayuri=explode("/",$urinow);
            $productid=$arrayuri[count($arrayuri)-1];
            
            if(is_numeric($productid))
            {
            $this->arraydata['data'][$k]['productid']=$productid;
            
            }else
            {
            $this->arraydata['data'][$k]['productid']='';
            }
            
            
            }else
            {
            
            $this->arraydata['data'][$k]['productid']='';
            }

            
            
            
            }else
            {
            
            $this->arraydata['data'][$k]['link']='';
            $this->arraydata['data'][$k]['tag']=str_replace('#','|',$valuedata['tag']) ;
            $this->arraydata['data'][$k]['productid']='';
            
            
            
            }
            
            
            
            
            $k++;
            
            }
            
            
            
            }
            
            
            }else
            {
            if(($this->info['configall']['banner']['mobile1']||$this->info['configall']['banner']['mobile']||$this->info['configall']['banner']['android']))
            {
            if((false !== stripos($_SERVER['HTTP_USER_AGENT'], 'ipad')))
            {
          //  $data['test']="ipad";
//            $data['createdate']=date("Y-m-d H:i:s");
//            $this->db->db_set($data,"tb_logtest");
            if(count($this->info['configall']['banner']['mobile1']))
            {
            $k=0;
            foreach($this->info['configall']['banner']['mobile1']['img'] as $valuebanner)
            {
            
            $this->arraydata['data'][$k]['banner']=bannerinfo.'/'.$valuebanner;
            $this->arraydata['data'][$k]['link']=$this->info['configall']['banner']['mobile1']['link'][$k];
            $this->arraydata['data'][$k]['productid']=$this->info['configall']['banner']['mobile1']['productid'][$k];
            
            list($width, $height, $type, $attr) =getimagesize(rootpath.'/assets/banner/'.$valuebanner);
            
            $this->arraydata['data'][$k]['ratio']=$width/$height;
            
            
            
        //    $data['test']=json_encode($this->arraydata['data'][$k]);
//            $data['createdate']=date("Y-m-d H:i:s");
//            $this->db->db_set($data,"tb_logtest");
           // $this->arraydata['data']['banner'][]=bannerinfo.'/'.$valuebanner;   
            $k++;
            }
            
            }
            
            
            
            }else if((false !== stripos($_SERVER['HTTP_USER_AGENT'], 'iphone')))
            {
            if(count($this->info['configall']['banner']['mobile']))
            {

            $k=0;
            foreach($this->info['configall']['banner']['mobile']['img'] as $valuebanner)
            {
            
            $this->arraydata['data'][$k]['banner']=bannerinfo.'/'.$valuebanner;
            $this->arraydata['data'][$k]['link']=$this->info['configall']['banner']['mobile']['link'][$k];
            $this->arraydata['data'][$k]['productid']=$this->info['configall']['banner']['mobile']['productid'][$k];
            

            
            list($width, $height, $type, $attr) =getimagesize(rootpath.'/assets/banner/'.$valuebanner);
            
            $this->arraydata['data'][$k]['ratio']=$width/$height;
           // $this->arraydata['data']['banner'][]=bannerinfo.'/'.$valuebanner;   
           
           
                       //$data['test']=json_encode($this->arraydata['data'][$k]);
//            $data['createdate']=date("Y-m-d H:i:s");
//            $this->db->db_set($data,"tb_logtest");
            $k++;
            }
            
            }
            }
            else
            {
            if(count($this->info['configall']['banner']['android']))
            {

            $k=0;
            foreach($this->info['configall']['banner']['android']['img'] as $valuebanner)
            {
            
            $this->arraydata['data'][$k]['banner']=bannerinfo.'/'.$valuebanner;
            $this->arraydata['data'][$k]['link']=$this->info['configall']['banner']['android']['link'][$k];
            $this->arraydata['data'][$k]['productid']=$this->info['configall']['banner']['android']['productid'][$k];
            

            
            list($width, $height, $type, $attr) =getimagesize(rootpath.'/assets/banner/'.$valuebanner);
            
            $this->arraydata['data'][$k]['ratio']=$width/$height;
           // $this->arraydata['data']['banner'][]=bannerinfo.'/'.$valuebanner;   
           
           
                       //$data['test']=json_encode($this->arraydata['data'][$k]);
//            $data['createdate']=date("Y-m-d H:i:s");
//            $this->db->db_set($data,"tb_logtest");
            $k++;
            }
            
            }
            
            
            
            }
            
            }else
            {
            if(count($this->info['configall']['banner']['web']))
            {
            $k=0;
            foreach($this->info['configall']['banner']['web']['img'] as $valuebanner)
            {
            
            $this->arraydata['data'][$k]['banner']=bannerinfo.'/'.$valuebanner;
            $this->arraydata['data'][$k]['link']=$this->info['configall']['banner']['web']['link'][$k];
            
            $productid=0;
            if($this->info['configall']['banner']['mobile']['productid'][$k])
            {
            $productid=$this->info['configall']['banner']['mobile']['productid'][$k];
            }
            $this->arraydata['data'][$k]['productid']=$productid;
            
            list($width, $height, $type, $attr) =getimagesize(rootpath.'/assets/banner/'.$valuebanner);
            
            $this->arraydata['data'][$k]['ratio']=$width/$height;
           // $this->arraydata['data']['banner'][]=bannerinfo.'/'.$valuebanner;   
            $k++;
            }
            
            }
            }
            }
            
            }
            
            
            
            function getloginfacebookbk()
            {
            
            require pluginpath.'/facebook/facebook.php';

            
            $facebook = new Facebook(array(
            'appId'  =>facebookappid,
            'secret' =>facebooksecret,
            ));
            
            
            $user = $facebook->getUser();
            
            
            if ($user) {
            try {
            // Proceed knowing you have a logged in user who's authenticated.
            $user_profile = $facebook->api('/me');
            } catch (FacebookApiException $e) {
            error_log($e);
            $user = null;
            }
            }
            
            
            
            if($this->userdata['oauth'])
            {
            $sql='select facebookid,username from tb_user where oauth="'.$this->userdata['oauth'].'" ';
            $arraycheckf=$this->db->db_set_1recordrow($sql);
            if($arraycheckf['facebookid']&&$user_profile['id'])
            {
            
            if($arraycheckf['facebookid']==$user_profile['id'])
            {
           
            
            
            }else
            {
            
            
            $logoutUrl=$facebook->getLogoutUrl(
            array(
            'next' => baseinfo.'/'.$arraycheckf['username'].'/friendssuggesion?logoutfacebook=1'));
            
            
            
        //  //  $loginUrl=$facebook->getLoginUrl(
//            array(
//            'redirect_uri' => baseinfo.'/ajax/getloginfacebook?noredirect=1&nojson=1&linkto=/'.$username.'/friendssuggesion',
//            'scope' => 'email,user_likes,user_photos,publish_stream,user_about_me,user_videos,status_update,user_birthday,user_location,user_work_history'));
//            
//            
//            $params = array(
//              'ok_session' => baseinfo.'/'.$arraycheckf['username'].'/friendssuggesion',
//              'no_user' => baseinfo.'/'.$arraycheckf['username'].'/friendssuggesion',
//              'no_session' => baseinfo.'/'.$arraycheckf['username'].'/friendssuggesion',
//            );

//$next_url = $facebook->getLoginStatusUrl($params);

            //echo $logoutUrl;
            redirectto($logoutUrl);
            exit;
            
            
       //
             
//       
//            redirectto($logoutUrl);
//            
//            exit;
            }
            
            
            }
            
            
            }
            

            
            $this->post['facebookid']=$user_profile['id'];
            $this->post['firstname']=$user_profile['first_name'];
            $this->post['lastname']=$user_profile['last_name'];
            $this->post['email']=$user_profile['email'];
            $this->post['pos']=1;
         

           // exit;

            
            if($this->post['facebookid'])
            {

            $this->login();

            
            }else
            {
            if($this->userdata['oauth'])
            {
                 $domain='';
                      if(NameDmconnex=="Canonlife"){
                      $url='http://'.$_SERVER['HTTP_HOST'];
                      $domain='.'.get_domain($url);
                      }
            $datauser=$this->getuserbyoauth($this->userdata['oauth']);
              if($datauser['roleid']=='3'||$datauser['roleid']=='4'||$datauser['roleid']=='5')
                {
                setcookie('poslogin',1, 0, "/",$domain);
                }
            
            }
            
            
            
            
            }
             if($_COOKIE['redirectto'])
             {
               $redirectto=$_COOKIE['redirectto'];
               $time=time()-3600000;   
               setcookie('redirectto','', $time, "/",$domain); 
               header('Location: '.baseinfo.'/'.$redirectto);
               exit;
             }
             
             $linkto=baseinfo;
             if($this->get['linkto'])
             {
             if(strpos($this->get['linkto'],'http')!==false)
             {
             $linkto=$this->get['linkto'];
             }else
             {
             $linkto=baseinfo.$this->get['linkto'];
             }
             
             }
             if($this->get['noredirectdata']==1)
             {
             
             }else
             {
             
             header('Location: '.$linkto);
             }
             
          
              
            
            }    
            
            function getloginfacebook()
            {
            
                   FacebookSession::setDefaultApplication(facebookappid,facebooksecret);  
                        $helper = new FacebookRedirectLoginHelper(baseinfo.'/ajax/getloginfacebook?noredirect=1&nojson=1');
                        
                        try {
  $session = $helper->getSessionFromRedirect();
} catch( FacebookRequestException $ex ) {
  // When Facebook returns an error
} catch( Exception $ex ) {
  // When validation fails or other local issues
}

       if ( isset( $session ) ) {
                      
                        $request = new FacebookRequest( $session, 'GET', '/me' );
  $response = $request->execute();
  // get response
  $graphObject = $response->getGraphObject();
  
                  
          if($this->userdata['oauth'])
            {
            $sql='select facebookid,username from tb_user where oauth="'.$this->userdata['oauth'].'" ';
            $arraycheckf=$this->db->db_set_1recordrow($sql);
            if($arraycheckf['facebookid']&&$graphObject->getProperty('id'))
            {
            
            if($arraycheckf['facebookid']==$graphObject->getProperty('id'))
            {
           
            
            
            }else
            {
            
            
            $logoutUrl=$helper->getLogoutUrl(
            array(
            'next' => baseinfo.'/'.$arraycheckf['username'].'/friendssuggesion?logoutfacebook=1'));
            
          
            redirectto($logoutUrl);
            exit;
            
            
       //
             
//       
//            redirectto($logoutUrl);
//            
//            exit;
            }
            
            
            }
            
            
            }
            
            $this->post['facebookid']=$graphObject->getProperty('id');
            $this->post['firstname']=$graphObject->getProperty('first_name');
            $this->post['lastname']=$graphObject->getProperty('last_name');
            $this->post['email']=$graphObject->getProperty('email');
            $this->post['pos']=1;
            
            
                   if($this->post['facebookid'])
            {

            $this->login();

            
            }else
            {
            if($this->userdata['oauth'])
            {
                 $domain='';
                      if(NameDmconnex=="Canonlife"){
                      $url='http://'.$_SERVER['HTTP_HOST'];
                      $domain='.'.get_domain($url);
                      }
            $datauser=$this->getuserbyoauth($this->userdata['oauth']);
              if($datauser['roleid']=='3'||$datauser['roleid']=='4'||$datauser['roleid']=='5')
                {
                setcookie('poslogin',1, 0, "/",$domain);
                }
            
            }
            
            
            
            
            }
             if($_COOKIE['redirectto'])
             {
               $redirectto=$_COOKIE['redirectto'];
               $time=time()-3600000;   
               setcookie('redirectto','', $time, "/",$domain); 
               header('Location: '.baseinfo.'/'.$redirectto);
               exit;
             }
             
             $linkto=baseinfo;
             if($this->get['linkto'])
             {
             if(strpos($this->get['linkto'],'http')!==false)
             {
             $linkto=$this->get['linkto'];
             }else
             {
             $linkto=baseinfo.$this->get['linkto'];
             }
             
             }
             if($this->get['noredirectdata']==1)
             {
             
             }else
             {
             
             header('Location: '.$linkto);
             }
             

                      }
            
            
            
            }        

             function getloginfacebooktestcase()
            {
            
            require pluginpath.'/facebook/facebook.php';

            
            $facebook = new Facebook(array(
            'appId'  =>facebookappid,
            'secret' =>facebooksecret,
            ));
            
            
            $user = $facebook->getUser();
            
            echo $user;
            exit;
            
            if ($user) {
            try {
            // Proceed knowing you have a logged in user who's authenticated.
            $user_profile = $facebook->api('/me');
            } catch (FacebookApiException $e) {
            error_log($e);
            $user = null;
            }
            }
            
            
            
            if($this->userdata['oauth'])
            {
            $sql='select facebookid,username from tb_user where oauth="'.$this->userdata['oauth'].'" ';
            $arraycheckf=$this->db->db_set_1recordrow($sql);
            if($arraycheckf['facebookid']&&$user_profile['id'])
            {
            
            if($arraycheckf['facebookid']==$user_profile['id'])
            {
           
            
            
            }else
            {
            
            
            $logoutUrl=$facebook->getLogoutUrl(
            array(
            'next' => baseinfo.'/'.$arraycheckf['username'].'/friendssuggesion?logoutfacebook=1'));
            
            
            
        //  //  $loginUrl=$facebook->getLoginUrl(
//            array(
//            'redirect_uri' => baseinfo.'/ajax/getloginfacebook?noredirect=1&nojson=1&linkto=/'.$username.'/friendssuggesion',
//            'scope' => 'email,user_likes,user_photos,publish_stream,user_about_me,user_videos,status_update,user_birthday,user_location,user_work_history'));
//            
//            
//            $params = array(
//              'ok_session' => baseinfo.'/'.$arraycheckf['username'].'/friendssuggesion',
//              'no_user' => baseinfo.'/'.$arraycheckf['username'].'/friendssuggesion',
//              'no_session' => baseinfo.'/'.$arraycheckf['username'].'/friendssuggesion',
//            );

//$next_url = $facebook->getLoginStatusUrl($params);

            //echo $logoutUrl;
            redirectto($logoutUrl);
            exit;
            
            
       //
             
//       
//            redirectto($logoutUrl);
//            
//            exit;
            }
            
            
            }
            
            
            }
            

            
            $this->post['facebookid']=$user_profile['id'];
            $this->post['firstname']=$user_profile['first_name'];
            $this->post['lastname']=$user_profile['last_name'];
            $this->post['email']=$user_profile['email'];
            $this->post['pos']=1;
           
            

           // exit;

            
            if($this->post['facebookid'])
            {
//            echo "<pre>";
//            print_r($this->post);
//            echo "</pre>;";
//            exit;
            $this->login();

            
            }else
            {
            if($this->userdata['oauth'])
            {
                 $domain='';
                      if(NameDmconnex=="Canonlife"){
                      $url='http://'.$_SERVER['HTTP_HOST'];
                      $domain='.'.get_domain($url);
                      }
            $datauser=$this->getuserbyoauth($this->userdata['oauth']);
              if($datauser['roleid']=='3'||$datauser['roleid']=='4'||$datauser['roleid']=='5')
                {
                setcookie('poslogin',1, 0, "/",$domain);
                }
            
            }
            
            
            
            
            }
            
             $linkto=baseinfo;
             if($this->get['linkto'])
             {
             if(strpos($this->get['linkto'],'http')!==false)
             {
             $linkto=$this->get['linkto'];
             }else
             {
             $linkto=baseinfo.$this->get['linkto'];
             }
             
             }
             if($this->get['noredirectdata']==1)
             {
             
             }else
             {
             
             header('Location: '.$linkto);
             }
             
          
              
            
            }            


            
            function getDoc()
            {


        if ($this->get['docid'])
            {

            $sql="SELECT
                 *
                FROM
                info_title
                INNER JOIN info_doc ON info_title.tid = info_doc.tid
                where  info_doc.docid=" . $this->get['docid'] . "
                ";
           $arraydata= $this->db->db_set_recordset($sql);

           
            $arraynewdata=array();


            if (count($arraydata))
                {
                $arraynewdata['data']=$arraydata[0];
                }

            $sql="SELECT * FROM info_parem where info_parem.docid=" . $this->get['docid'];
            $arraydata=$this->db->db_set_recordset($sql);


            if (count($arraydata))
                {
                $arraynewdata['key']=$arraydata;
                }
                
                
                $this->arraydata=$arraynewdata;

            }     
        
        }
            function getinfophp()
            {
            phpinfo();
            
            }
            function getinfo()
            {
            //echo "<pre>";
//            print_r($this->info['configall']);
//            echo "</pre>;";

            if(count($this->info['configall']['feature']))
            {
            $k=0;
            foreach($this->info['configall']['feature'] as $valuefeature)
            {
                 if(count($valuefeature['plugins']))
                 {
                 $x=0;
                      foreach($valuefeature['plugins'] as $valueplugins)
                      {
                      
                         if($valueplugins['plugid']==12)
                         {
                         
                             $this->info['configall']['feature'][$k]['showadd']=intval($this->info['configall']['feature'][$k]['showadd']);
                             unset($this->info['configall']['feature'][$k]['plugins'][$x]);
                         
                         
                         }
                          $x++;
                      }
                 
                 
                 }
             $k++;
            }
            
            }

            $this->arraydata['data']=$this->info['configall'];
            
            
            
            }
            
            //function readallnotification()
//            {
//            
//            if($this->userdata['oauth'])
//            {
//             
//             $arrayuser=$this->getuserbyoauth($this->userdata['oauth']);
//             if($arrayuser['userid'])
//             {
//             $arraydata['badge']=0;
//             $this->db->db_set($arraydata,'tb_user',' userid='.$arrayuser['userid']);
//             
//               $sql="select notiid,tb_notification.read,notifyid from tb_notification where notifyid<>0";
//            $notificationbox=$this->db->db_set_recordset($sql);
//            if(count($notificationbox))
//            {
//            foreach($notificationbox as $valuenoti)
//            {
//            if($valuenoti['notifyid']!=0)
//            {

//            if($this->checkreadnotify($arrayuser['userid'],$valuenoti['notifyid'])===false)
//            {
//                $arraydata=array();
//               $arraydata['notifyid']=$valuenoti['notifyid'];
//               $arraydata['userid']=$arrayuser['userid'];
//               $arraydata['status']=1;
//               $arraydata['createdate']=date("Y-m-d H:i:s");
//               $this->db->db_set($arraydata,'tb_read_notify');
//               
//            
//            }
//            
//            
//            }
//            }
//            }
//            
//            

//             $arraydata=array();
//              $arraydata['read']=1;
//              $this->db->db_set($arraydata,'tb_notification',' userid='.$arrayuser['userid']);
//            
//            
//          
//             
//             
//             
//             }else
//             {
//             
//           $this->arraydata['error'][]=11;
//             
//             
//             
//             
//             }
//            
//            
//            
//            }else
//            {
//            $this->arraydata['error'][]=11;
//            
//            }
//            
//            
//            
//            
//            
//            
//            }
            function readallnotification()
            {
            if($this->userdata['oauth'])
            {
            $arrayuser=$this->getuserbyoauth($this->userdata['oauth']);
            if($arrayuser['userid'])
            {
            $sql="select notiid,tb_notification.read,notifyid from tb_notification where userid=".$arrayuser['userid'];
            $notificationboxall=$this->db->db_set_recordset($sql);
            if(count($notificationboxall))
            {
            foreach($notificationboxall as $notificationbox )
            {
            if($notificationbox['notifyid']!=0)
            {

            if($this->checkreadnotify($arrayuser['userid'],$notificationbox['notifyid'])===false)
            {
            
               $arraydata['notifyid']=$notificationbox['notifyid'];
               $arraydata['userid']=$arrayuser['userid'];
               $arraydata['status']=1;
               $arraydata['createdate']=date("Y-m-d H:i:s");
               $this->db->db_set($arraydata,'tb_read_notify');
               
               
              // $sql="select badge from tb_user where userid=".$arrayuser['userid'];
//               $userdata=$this->db->db_set_1recordrow($sql);
//               if($userdata['badge'])
//               {
//                $userdata['badge']=$userdata['badge']-1;
//                $this->db->db_set($userdata,'tb_user',' userid='.$arrayuser['userid']);
//                
//               }
               
            
            }
            
            
            }
            else if($notificationbox['read']==0)
            {
            
              $arraydata['read']=1;
              $this->db->db_set($arraydata,'tb_notification',' notiid='.$notificationbox['notiid']);
              
              //$sql="select badge from tb_user where userid=".$arrayuser['userid'];
//               $userdata=$this->db->db_set_1recordrow($sql);
//              if($userdata['badge'])
//               {
//                $userdata['badge']=$userdata['badge']-1;
//                $this->db->db_set($userdata,'tb_user',' userid='.$arrayuser['userid']);
//                
//               }
            
            
            }
            }
            
                 
            
            }
            $userdata['badge']=0;
            $this->db->db_set($userdata,'tb_user',' userid='.$arrayuser['userid']);
            
            
            }
            
            }
            
            
            
            }
            function savereport()
            {
            
            if($this->post['report'])
            {
             $arraydata['typeid']=$this->post['type'];
             $arraydata['report']=$this->post['report'];
             if($this->post['userid'])
             {
             $arraydata['userid']=$this->post['userid'];
             }
             if($this->post['productid'])
             {
             $arraydata['productid']=$this->post['productid'];
             }
             if($this->userdata['userid'])
             {
             $arraydata['createby']=$this->userdata['userid'];
             }
             
             $arraydata['createdate']=date("Y-m-d H:i:s");
             $this->db->db_set($arraydata,"tb_report");
             
            
            
            }
            
            
            }
            
            function readallbadge()
            {
            
            if($this->userdata['oauth'])
            {
             
             $arrayuser=$this->getuserbyoauth($this->userdata['oauth']);
             if($arrayuser['userid'])
             {
             
             $arraydata['badge']=0;
             $this->db->db_set($arraydata,'tb_user',' userid='.$arrayuser['userid']);
             
           
            
            
          
             
             
             
             }else
             {
             
           $this->arraydata['error'][]=11;
             
             
             
             
             }
            
            
            
            }else
            {
            $this->arraydata['error'][]=11;
            
            }
            
            
            
            
            
            
            }
            
            //start 2-09-2556
            function getproductbytagname()
            {
            if($this->get['page']&&$this->get['tagname']&&$this->get['amount'])
            {
            
            $page=(($this->get['page'] - 1) * $this->get['amount']);
            $this->arraydata['data']=parent::getproductbytagname($this->get['tagname'],$page,$this->get['amount']);
            
            }
            
            
            }
            
            
            //end 2-09-2556 
        
        
            //start 4-09-2556
        
           function saveproductmobiledata()
            {
             
             if($this->post['data'])
             {
            
            $this->post['data']=stripcslashes($this->post['data']);
          
            $this->post['data']=json_decode($this->post['data']);
            
            $this->post['data']=object_to_array($this->post['data']);
            
            
            $this->userdata=$this->getuserbyusername($this->post['data']['username']);
            $this->post=$this->post['data'];

             
             }
            $oauth=$this->userdata['oauth'];
            $arrayuser=$this->getuserbyoauth($oauth);
            if($arrayuser['userid']&&$this->post)
            {


            
            $arraydata['title']=  $this->post['title'];
            
            getFilesFromDirMuti(includepath,$arraynow);
             if(array_search_r_like($this->post['title'], $arraynow)||array_search_r_like($this->post['title'], $this->info['configall']['feature']))
            {
            $this->post['title']=$this->post['title'].'1';
            }
            
            $arraydata['link']=str_replace(array("/"," ","?","&",";"),"-",strip_tags(trim($this->post['title']))) ;
            
            $arraydata['description']=$this->post['description'];
            $arraydata['fid']=$this->post['fid'];
            $arraydata['infoid']=$this->post['infoid'];
            
            if($this->post['photomain'])
            {
            $arraydata['imgmid']= $this->savephotobase64($this->post['photomain']);
            $arraydata['simgmid']=$arraydata['imgmid'];
            
            }else if($this->post['photolink'])
            {
            $arraydata['imgmid']=$this->savephotolink($this->post['photolink']);
            $arraydata['simgmid']=$this->savephotolink($this->post['photolink'],600,600);
            
            }
            
            
                                                                                   
            $arraydata['idref']=$this->post['idref'];
            $arraydata['status']=$this->post['status'];
            $arraydata['updateby']=$arrayuser['userid'];
             if($this->post['createdate'])
            {
            $arraydata['updatedate']=$this->post['createdate'];
            }else{
            $arraydata['updatedate']=date("Y-m-d H:i:s");
            }
            
            if($this->post['code'])
            {
            $arraydata['code']=$this->post['code'];
            }
            
            if(isset($this->post['ispoi']))
            {
            $arraydata['ispoi']=$this->post['ispoi'];
            }
            
            if($this->post['productid'])
            {
            
            $this->db->db_set($arraydata,"tb_product",' productid="'.$this->post['productid'].'"');
            $productid=$this->post['productid'];
            }
            else
            {
            $set=1;
            $arraydata['createby']=$arrayuser['userid'];
            if($this->post['createdate'])
            {
            $arraydata['createdate']=$this->post['createdate'];
            }else
            {
            $arraydata['createdate']=date("Y-m-d H:i:s");
            }
            
            $this->db->db_set($arraydata,"tb_product");
            $productid=$this->db->db_get_last_number();
            //$this->savescoredata($arrayuser['userid'],3);
            $this->savegamenictaionbygxcid($arrayuser['userid'],3);
            }
            
            if($set)
            {
            if(!is_dir(imgpath.'/'.$productid))
            {
            mkdir(imgpath.'/'.$productid,0777);
            chmod(imgpath.'/'.$productid,0777);
            }
            if(!is_dir(filepath.'/'.$productid))
            {
            mkdir(filepath.'/'.$productid,0777);
            chmod(filepath.'/'.$productid,0777);
            }
            
            
            }
            
            
            $arraydata2['imgmid']=$this->swicthpathimage($arraydata['imgmid'],$productid,1);
            $arraydata2['simgmid']=$this->swicthpathimage($arraydata['simgmid'],$productid,1);
            $this->db->db_set($arraydata2,"tb_product",' productid="'.$productid.'"');
            $taguser="";
            if(count($this->post['taguser']))
            {
            foreach($this->post['taguser'] as $valueuser)
            {
            
            $taguser.=" #".$valueuser;
            
            }
            
            }
            
            $this->savetag($this->post['tagsystem'],$taguser,$productid,$this->post['fid']);
            
           // $plugins[]=array('plugid'=>14,"imgmid"=>$arraydata2['imgmid'],"simgmid"=>$arraydata2['imgmid'],"detail"=>$detail);
            
            
            
            if(count($this->post['plugin']))
            {
            $this->saveplugins($this->post['plugin'],$productid);
            }
            
            
            
            $this->arraydata['data']['link']=$arraydata['link'];
            $this->arraydata['data']['productid']=$productid;
            
            }
            else
            {
            $this->arraydata['error'][]=4;
            
            }
            
            }
            
            function savememberdata()
            {
            $this->post['data']=stripcslashes($this->post['data']);
          
            $this->post['data']=json_decode($this->post['data']);
            
            $this->post['data']=object_to_array($this->post['data']);
            if(count($this->post['data']))
            {
             foreach($this->post['data'] as $valuepost)
             {
             if($valuepost['facebookid'])
             {
             
             $this->loginfacebook($valuepost['facebookid'],$valuepost['email'],$valuepost['firstname'],$valuepost['lastname'],$valuepost['gender']);
             
             }else if($valuepost['username']&&$valuepost['email']&&$valuepost['password'])
           {
           
           $username=$valuepost['username'];
           $check1=$this->checkusername($username);
           
           $email=$valuepost['email'];
           $check2=$this->checkemail($email);
          
           if($check1==1&&$check2==1)
           {
           
           $userArray['username']=$username;
           $userArray['displayname']=$username;
           $userArray['email']=$email;
         //  $md5password=md5($this->post['password'].'-123456');
           $userArray['password']=$valuepost['password'];
           if(trim($valuepost['oauth']))
           {
           $userArray['oauth']=$valuepost['oauth'];
           }else
           {
           $userArray['oauth']=md5(mktime().$userArray['password']);
           
           }
           
           $userArray['phone']=$valuepost['phone'];
           $userArray['firstname']=$valuepost['firstname'];
           $userArray['lastname']=$valuepost['lastname'];
           $userArray['proid']=$valuepost['proid'];
           $userArray['disid']=$valuepost['disid'];
           $userArray['tumid']=$valuepost['tumid'];  
           if($valuepost['roleid'])
           {
              $userArray['roleid']=$valuepost['roleid'];
           } else
           {
              $userArray['roleid']=1;
           }
            
           $userArray['lat']=$valuepost['lat'];
           $userArray['lng']=$valuepost['lng'];
           $userArray['countryid']=$valuepost['countryid'];
           $userArray['state']=$valuepost['state'];
           $userArray['status']=$valuepost['status'];
           
           $userArray['code']=$valuepost['code'];
           $userArray['facebookid']=$valuepost['facebookid'];
           $userArray['gender']=$valuepost['gender'];
           
           $this->saveregister($userArray,1);
           
           
           
        //   require_once(pluginpath.'/phpmailer/class.config.php'); // uri
//           
//           $mail = new ConfigMail();
           //$mail->setFrom("s_chanyut@hotmail.com","Bird Kung");
//           $mail->setTo($email,$username);
//           $mail->setContent('Confirm Now  <br> <a href="'.baseinfo.'/ajax/confirmuser?oauth='.$userArray['oauth'].'&nojson=1" target="_blank">Click here</a>');
//           $mail->setSubject("Confirm New User From ".NameDmconnex);
//           $mail->sendTo();
           
           
           
           
           }else
           {
           if($check1!=1)$this->arraydata['error'][]=$check1;
           if($check2!=1)$this->arraydata['error'][]=$check2;

           
           }
           
           
           
           
           }else
           {
           $this->arraydata['error'][]=4;
           
           }
           
            }
            
            }
            
            }
            
            
            function savememberdatacanon()
            {
            exit;
            $arraynewdata=array();
            $sql='SELECT * FROM  `icweb_cms_member`where icweb_cms_member_ID>=14423  order by icweb_cms_member_ID asc';
            $arraydata=$this->db->db_set_recordset($sql);
            $this->arraydata['data']=$arraydata;
            
            $k=0;
            if(count($arraydata))
            {
            foreach($arraydata as $valuedata)
            {
            list($username,$domain)=explode("@",$valuedata['icweb_cms_member_Username']);
            
           
            $arraynewdata[$k]['username']=$username;
         
            
            
            $arraynewdata[$k]['password']=$valuedata['icweb_cms_member_Password'];
            $arraynewdata[$k]['displayname']=$valuedata['icweb_cms_member_Display'];
            $arraynewdata[$k]['firstname']=$valuedata['icweb_cms_member_Name'];
            $arraynewdata[$k]['lastname']=$valuedata['icweb_cms_member_LastName'];
            $arraynewdata[$k]['email']=$valuedata['icweb_cms_member_Username'];
            
            if($valuedata['icweb_cms_member_Sex']=="ชาย")
            {
            $arraynewdata[$k]['gender']=1;
            }else
            {
            $arraynewdata[$k]['gender']=2;
            
            }
            
            $arraynewdata[$k]['birthdate']=$valuedata['icweb_cms_member_Birthday'];
            $arraynewdata[$k]['phone']=$valuedata['icweb_cms_member_Mobile'];
            $arraynewdata[$k]['status']=1;
            $arraynewdata[$k]['salt']=1;
            
            
            
            
            $k++;
            
            }
            
            
            }
            
            
            
            $sql='SELECT * FROM `canonlife_users_entity` order by guid asc ';
            $arraydata2=$this->db->db_set_recordset($sql);
            if(count($arraydata2))
            {
            foreach($arraydata2 as $valuedata)
            {
            list($username,$domain)=explode("@",$valuedata['username']);
            
            //$check1=$this->checkusername($username);

            $arraynewdata[$k]['username']=$username;
         
            
            $arraynewdata[$k]['password']=$valuedata['password'];
            $arraynewdata[$k]['displayname']=$valuedata['name'];
            $arraynewdata[$k]['firstname']='';
            $arraynewdata[$k]['lastname']='';
            $arraynewdata[$k]['email']=$valuedata['email'];
            
          
            $arraynewdata[$k]['gender']=0;
            
       
            
            

            $arraynewdata[$k]['status']=1;
            $arraynewdata[$k]['salt']=$valuedata['salt'];
            
            
            
            
            $k++;
            
            }
            
            }
            
//            echo "<pre>";
//            print_r($arraynewdata);
//            echo "</pre>;";
          // $this->arraydata['data']=$arraynewdata;
         //   exit;
         $this->post['data']=$arraynewdata;
            if(count($this->post['data']))
            {
             foreach($this->post['data'] as $valuepost)
             {
             if($valuepost['facebookid'])
             {
             
             $this->loginfacebook($valuepost['facebookid'],$valuepost['email'],$valuepost['firstname'],$valuepost['lastname'],$valuepost['gender']);
             
             }
             else if($valuepost['username']&&$valuepost['email']&&$valuepost['password'])
           {
           
           $username=$valuepost['username'];
           $check1=$this->checkusername($username);
           
           $email=$valuepost['email'];
           $check2=$this->checkemail($email);
           
           if($check1!=1)
           {
           $username=$username.time().'-'.rand(1,3000);
           
           }
          
           if($check2==1)
           {
           
           $userArray['username']=$username;
           $userArray['displayname']=$valuepost['displayname'];
           $userArray['email']=$email;
         //  $md5password=md5($this->post['password'].'-123456');
           $userArray['password']=$valuepost['password'];
           if(trim($valuepost['oauth']))
           {
           $userArray['oauth']=$valuepost['oauth'];
           }else
           {
           $userArray['oauth']=md5(mktime().$userArray['password']);
           
           }
           
           $userArray['phone']=$valuepost['phone'];
           $userArray['firstname']=$valuepost['firstname'];
           $userArray['lastname']=$valuepost['lastname'];

           $userArray['salt']=$valuepost['salt'];
           $userArray['gender']=$valuepost['gender'];
            
           if($valuepost['roleid'])
           {
              $userArray['roleid']=$valuepost['roleid'];
           } else
           {
              $userArray['roleid']=1;
           }
            
           //$userArray['lat']=$valuepost['lat'];
           //$userArray['lng']=$valuepost['lng'];
           $userArray['countryid']=210;
           //$userArray['state']=$valuepost['state'];
           $userArray['status']=$valuepost['status'];
           
           //$userArray['code']=$valuepost['code'];
           //$userArray['facebookid']=$valuepost['facebookid'];
           $userArray['gender']=$valuepost['gender'];
           
           $this->saveregister($userArray,1);
           
           $this->arraydata['data1'][]=$valuepost;
           
        //   require_once(pluginpath.'/phpmailer/class.config.php'); // uri
//           
//           $mail = new ConfigMail();
           //$mail->setFrom("s_chanyut@hotmail.com","Bird Kung");
//           $mail->setTo($email,$username);
//           $mail->setContent('Confirm Now  <br> <a href="'.baseinfo.'/ajax/confirmuser?oauth='.$userArray['oauth'].'&nojson=1" target="_blank">Click here</a>');
//           $mail->setSubject("Confirm New User From ".NameDmconnex);
//           $mail->sendTo();
           
           
           
           
           }else
           {
           
           $this->arraydata['data2'][]=$valuepost;
         //  if($check1!=1)$this->arraydata['error'][]=$check1;
          // if($check2!=1)$this->arraydata['error'][]=$check2;

           
           }
           
           
           
           
           }else
           {
           $this->arraydata['error'][]=4;
           
           }
           
            }
            
            }
            
            }
            
            function changevalueoauth()
            {
            $sql="select userid,username from tb_user where oauth=''";
            $arraydata=$this->db->db_set_recordset($sql);
            if(count($arraydata))
            {
            
            foreach($arraydata as $valuedata)
            {
            
            $userArray['oauth']=md5(mktime().$valuedata['username']);
            $this->db->db_set($userArray,'tb_user',' userid='.$valuedata['userid']);
            
            }
            
            }
            
            
            
            }
            
           
            
               //start 6-09-2556 
            function getmedthodplugin()
            {
            if($this->get['classset']&&$this->get['medthodset'])
            {
            eval("\$obj = new Plugins_".ucfirst($this->get['classset']).'($this->db);');
            if(count($this->get['parem']))
            {
            $strparem=array();
            foreach($this->get['parem'] as $valueparem)
            {
            
            if(is_numeric($valueparem))
            {
            $strparem[]=$valueparem;
            }else
            {
            
            $strparem[]='"'.$valueparem.'"';
            }
            
            
            }
            
            
     
            eval("\$value=\$obj->".$this->get['medthodset'].'('.join(',',$strparem).');');
            }else
            {
            eval("\$value=\$obj->".$this->get['medthodset'].'();');
            }
            
            $this->arraydata['data']=$value['data'];
            if($value['error']){$this->arraydata['error']=$value['error'];}
            
            }
            
            
            }
            
            function postmedthodplugin()
            {
            
            //$arraylog['test']=json_encode($this->post); 
           // $this->db->db_set($arraylog,'tb_log');

                       if($this->post['classset']&&$this->post['medthodset'])
            {
            eval("\$obj = new Plugins_".ucfirst($this->post['classset']).'($this->db,$this->userdata,$this->post);');
            
            if($this->post['medthodset']=='savecomment')
            {
            if($this->post['parem'][0])
            {
            $_POST['msg']=$this->post['parem'][0];
            
            }
            
            if($this->post['parem'][1])
            {
            $_POST['productid']=$this->post['parem'][1];
            
            }
            
            
            
            unset($this->post['parem']);
            
            }
            
            if(count($this->post['parem']))
            {
            
            
            $strparem=array();
            foreach($this->post['parem'] as $valueparem)
            {
            
            if(is_numeric($valueparem))
            {
            $strparem[]=$valueparem;
            }else
            {
            
            $strparem[]='"'.$valueparem.'"';
            }
            
            
            }
            
            eval("\$value=\$obj->".$this->post['medthodset'].'('.join(',',$strparem).');');
            }else
            {
            
            eval("\$value=\$obj->".$this->post['medthodset'].'();');
            }
            
            
            if($value['data'])
            {
             $this->arraydata['data']=$value['data'];  
            }else
            {
                 $this->arraydata['data']=$value;  
            
            }
            
            if($value['error']){$this->arraydata['error']=$value['error'];}
            
            }
            
            
            }
            
               //end 6-09-2556
               
               //start 11-09-2556  
            function  statdatabanner()
            {
            
             if($this->post['bannerid'])
             {
             $arraydata['bannerid']=$this->post['bannerid'];
            $arraydata['uuid']=$this->post['uuid'];
            $arraydata['ip']=$_SERVER['REMOTE_ADDR'];
            $arraydata['agent']=$_SERVER['HTTP_USER_AGENT'];
            if($this->userdata['userid'])
            {
            $arraydata['createby']=$this->userdata['userid'];
            }else
            {
            $arraydata['createby']=0;
            }
            
            $arraydata['createdate']=date("Y-m-d H:i:s");
            $this->db->db_set($arraydata,'tb_banner_stat');
             }
            
            
            }
            
            
            function checkvalidateapple()
           {
            if($this->post['check'])
            {
            require_once(rootpath.'/library/plugins/general_pi.php'); // uri
            if($this->post['check']==1)
            {
            $path="sandbox";
            }else
            {
            $path="buy";
            }
            
            $receipt = json_encode(array("receipt-data" => $path)); // NOTE: use "buy" vs "sandbox" in production.
             
             $_POST['receipt-data']=$path;
             unset($this->post["receipt"]);

             $url="https://".$path.".itunes.apple.com/verifyReceipt";
             $response_json = FetchContent($url,'','C:\Documents and Settings\Administrator\Local Settings\Temporary Internet Files\cookies.txt',$url,json_encode($_POST),1);

           $response = json_decode($response_json);

           $this->arraydata['error']= $response->{'status'};
            }
           }
            
               
               
               //end 11-09-2556  
               
         function importfile()
     {
     $this->db->get_connect(); 
     require_once( pluginpath.'/parsecsv/parsecsv.lib.php');
     
     $fileName=filepath.'/sukjai/2.csv';
     $pathfiledata=filepath.'/sukjai/folder';
     $csv = new parseCSV();
     $csv->auto($fileName);
     
     
     
     
     
 //    echo "<pre>";
//     print_r($csv->data);
//     echo "</pre>;";
//     exit;


     
      
     // $folderset=str_replace("shop2_c/","shop2_c",$folderset) ;
     $rowdatapath=1;
     


     if(count($csv->data))
     {
     foreach($csv->data as $valuedata)
     {
     
     $path=$pathfiledata.'/'.$valuedata['Image'];
     
     if(is_file(str_replace('.jpg','.JPG',$path)))
     {
         $path=str_replace('.jpg','.JPG',$path);
     }else if(is_file(str_replace('.jpg','.png',$path)))
     {
         $path=str_replace('.jpg','.png',$path);
     }
     
            $arrayuser=$this->getuserbyusername($valuedata['Username']);



            if($valuedata['Title']&&is_file($path)&&$arrayuser['userid'])
            {
            
            
            
            

              $this->post=array();
              $this->post['title']=$valuedata['Title'];
              $this->post['description']=$valuedata['Description'];
              $this->post['photopath']=$path;
              
              $this->post['fid']=$valuedata['Feature (app)'];
              $this->post['infoid']=1;
              $this->post['status']=1;

              $this->post['ispoi']=1;
              $this->post['taguser'][]=$valuedata['Tag1'];
              $this->post['taguser'][]=$valuedata['Tag2'];
              
              $this->post['tagsystem']=array();
              
              $this->post['plugin'][]=array('plugid'=>14,'photopath'=>$this->post['photopath'],'detail'=>'');
              
             // echo "<pre>";
//              print_r($this->post);
//              echo "</pre>;";
//              exit;
              
              if(is_file($pathfiledata.'/'.$valuedata['Gallery1']))
              {
              
              
              
              
              $this->post['plugin'][]=array('plugid'=>3,'imgmids'=>array(
              
              array('photopath'=>$pathfiledata.'/'.$valuedata['Gallery1'],'detail'=>'') , 
              array('photopath'=>$pathfiledata.'/'.$valuedata['Gallery2'],'detail'=>'') ,
              array('photopath'=>$pathfiledata.'/'.$valuedata['Gallery3'],'detail'=>'') ,
              array('photopath'=>$pathfiledata.'/'.$valuedata['Gallery4'],'detail'=>'') ,
              
              
              
              ));
              
              }
              
              
              if($valuedata['Address'])
              {
              
              $this->post['plugin'][]=array(
              'plugid'=>1,
              'alltime'=>$valuedata['IsAllTime'],
              'openhours'=>$valuedata['StartTime'],
              'closehours'=>$valuedata['EndTime'],
              'infomation'=>$valuedata['EtcTime'],
              'sameaddressprofile'=>0,
              'address'=>$valuedata['Address'],
              'countryid'=>$valuedata['Countryid'],
              'proid'=>$valuedata['Proid'],
              'disid'=>$valuedata['Disid'],
              'tumid'=>$valuedata['Tumid'],
              'state'=>'',
              'code'=>$valuedata['Code'],
              'samecontactprofile'=>0,
              'facebook'=>$valuedata['Facebook'],
              'twitter'=>$valuedata['Twitter'],
              'googleplus'=>$valuedata['Google+'],
              'email'=>$valuedata['Email'],
              'website'=>$valuedata['Website'],
              'phone'=>$valuedata['Phone'],
              'fax'=>$valuedata['Fax'],
              'etc'=>$valuedata['ETC'],
              );
              
              }
              
              if($valuedata['Text'])
              {

              $this->post['plugin'][]=array('plugid'=>8,'text'=>$valuedata['Text']);
              }
              
              if($valuedata['VDO'])
              {

              $this->post['plugin'][]=array('plugid'=>10,'url'=>$valuedata['VDO'],'embed'=>$embed);
              }
              
              if($valuedata['Map'])
              {
              list($lat,$lng)=explode("|",$valuedata['Map']);
              $this->post['plugin'][]=array('plugid'=>5,'lat'=>$lat,'lng'=>$lng,'detail'=>'');
              
              }
              
              
              
              
              
               
              
              
            
            getFilesFromDirMuti(includepath,$arraynow);
             if(array_search_r_like($this->post['title'], $arraynow)||array_search_r_like($this->post['title'], $this->info['configall']['feature']))
            {
            $this->post['title']=$this->post['title'].'1';
            }
            $arraydata['title']=$this->post['title'];
            
            $arraydata['link']=str_replace(array("/"," ","?","&",";"),"-",strip_tags(trim($this->post['title']))) ;
            
            $arraydata['description']=$this->post['description'];
            $arraydata['fid']=$this->post['fid'];
            $arraydata['infoid']=$this->post['infoid'];
            
            
            if($this->post['photomain'])
            {
            $arraydata['imgmid']= $this->savephotobase64($this->post['photomain']);
            $arraydata['simgmid']=$arraydata['imgmid'];
            
            }else if($this->post['photolink'])
            {
            $arraydata['imgmid']=$this->savephotolink($this->post['photolink']);
            $arraydata['simgmid']=$this->savephotolink($this->post['photolink'],300,300);
            
            }
            else if($this->post['photopath'])
            {
            $arraydata['imgmid']=$this->savephotopath($this->post['photopath']);
            $arraydata['simgmid']=$this->savephotopath($this->post['photopath'],300,300);
            
            }
            
            
                                                                                   

            $arraydata['status']=$this->post['status'];
            $arraydata['updateby']=$arrayuser['userid'];
             if($this->post['createdate'])
            {
            $arraydata['updatedate']=$this->post['createdate'];
            }else{
            $arraydata['updatedate']=date("Y-m-d H:i:s");
            }
            
            if($this->post['code'])
            {
            $arraydata['code']=$this->post['code'];
            }
            
            if(isset($this->post['ispoi']))
            {
            $arraydata['ispoi']=$this->post['ispoi'];
            }
            
            if($this->post['productid'])
            {
            
            $this->db->db_set($arraydata,"tb_product",' productid="'.$this->post['productid'].'"');
            $productid=$this->post['productid'];
            }
            else
            {
            $set=1;
            $arraydata['createby']=$arrayuser['userid'];
            if($this->post['createdate'])
            {
            $arraydata['createdate']=$this->post['createdate'];
            }else
            {
            $arraydata['createdate']=date("Y-m-d H:i:s");
            }
            
            $this->db->db_set($arraydata,"tb_product");
            $productid=$this->db->db_get_last_number();
            }
            
            if($set)
            {
            if(!is_dir(imgpath.'/'.$productid))
            {
            mkdir(imgpath.'/'.$productid,0777);
            chmod(imgpath.'/'.$productid,0777);
            }
            if(!is_dir(filepath.'/'.$productid))
            {
            mkdir(filepath.'/'.$productid,0777);
            chmod(filepath.'/'.$productid,0777);
            }
            
            
            }
            
            
            $arraydata2['imgmid']=$this->swicthpathimage($arraydata['imgmid'],$productid,1);
            $arraydata2['simgmid']=$this->swicthpathimage($arraydata['simgmid'],$productid,1);
            $this->db->db_set($arraydata2,"tb_product",' productid="'.$productid.'"');
            $taguser="";
            if(count($this->post['taguser']))
            {
            foreach($this->post['taguser'] as $valueuser)
            {
            
            $taguser.=" #".$valueuser;
            
            }
            
            }
            
            $this->savetag($this->post['tagsystem'],$taguser,$productid,$this->post['fid']);
            
           // $plugins[]=array('plugid'=>14,"imgmid"=>$arraydata2['imgmid'],"simgmid"=>$arraydata2['imgmid'],"detail"=>$detail);
            
            
            
            if(count($this->post['plugin']))
            {
            $this->saveplugins($this->post['plugin'],$productid);
            }
            

            
            
            $this->arraydata['data']['link']=$arraydata['link'];
            $this->arraydata['data']['productid']=$productid;
                     //   exit;
            
            }    
             else
             {
     
                echo      'no path '.$path.''."<br>"; 
             }
             
            // exit;
     
     }
     
     }
     
       $this->db->closedb(); 
     }
     
     
     
          function getbackendbanner()
          {
          
             
              $userdata=$this->getuserbyoauth($this->userdata['oauth']);
              if($this->post['deviceset']&&$userdata['roleid']==3)
              {

              
              $sql="select * from tb_backend_banner where deviceset=".$this->post['deviceset'];
              
              $arraydata=$this->db->db_set_1recordrow($sql);
              
              if(!$arraydata['backid'])
              {
              
              $arraydataset['deviceset']=$this->post['deviceset'];
              $arraydataset['bannershow']=1;
              
              $this->db->db_set($arraydataset,'tb_backend_banner');
              
              
              }else
              {
              
              $arraydataset['deviceset']=$this->post['deviceset'];
              $arraydataset['bannershow']=intval($arraydata['bannershow']);
              }
              
              
              
              $sql='SELECT * FROM `tb_banner` where status='.$this->post['deviceset'];;
              $arraybanner=$this->db->db_set_recordset($sql);
              
              if(count($arraybanner))
              {
              $k=0;
              foreach($arraybanner as $valuebanner)
              {
              
              if($valuebanner['imgmid'])
              {
              
              $arraybanner[$k]['imgarray'] =$this->getimagebyimgmid($valuebanner['imgmid']);
              
              }else
              {
              if(is_file(rootpath.'/assets/banner/'.$valuebanner['img']))
              {
              list($width, $height, $type, $attr) = getimagesize(rootpath.'/assets/banner/'.$valuebanner['img']);
              $arraybanner[$k]['imgarray']=array('newpath'=>bannerinfo.'/'.$valuebanner['img'],'width'=>$width,'height'=>$height);
              }else
              {
              
              $arraybanner[$k]['imgarray'] =$this->getimagebyimgmid(0);
              }
              }
              $k++;
              
              
              
              
              }
              
              }
              
              
              
              
              $arraydataset['banner']=$arraybanner;
              
              $this->arraydata['data']=$arraydataset;
              
              
              
              
              
              
              
               
              
              
              }
          
          
          
          }
          
          function savebackendbanner()
          {
             $userdata=$this->getuserbyoauth($this->userdata['oauth']);
             if($this->post['deviceset']&&$userdata['roleid']==3)
              {
              
                //$arraydataset['status']=0;
                //$this->db->db_set($arraydataset,"tb_banner",'status='.$this->post['deviceset']);
                
                
                if(count($this->post['banner']))
                {
                foreach($this->post['banner'] as $valuebanner)
                {
                
                if(strpos($valuebanner['link'],baseinfo)!==false)
                {
                $arraylink=explode("/",$valuebanner['link']);
                $strlast=$arraylink[count($arraylink)-1];
                if(is_numeric($strlast))
                {
                
                $valuebanner['productid']=$strlast;
                
                }
                
                
                }
                
                if($valuebanner['imgmid'])
                {
                $imgarrpath=$this->getimagebyimgmid($valuebanner['imgmid']);
                
                $imgarrpath['newpath']=str_replace(baseinfo,rootpath,$imgarrpath['newpath']);
                 $arraypath=explode("/",$imgarrpath['newpath']);
                 
                 list($name,$ext)=explode(".",$arraypath[count($arraypath)-1]);
                 $newname=$name.'-'.time().'.'.$ext;
                
                //chmod(rootpath.'/assets/banner/',0777);
                copy($imgarrpath['newpath'],rootpath.'/assets/banner/'.$newname);
                 
                 $valuebanner['img']=$newname;
                
                }
                
                if($valuebanner['bannerid'])
                {
              
                $bannerid=$valuebanner['bannerid'];

                
                unset($valuebanner['bannerid']);
                $this->db->db_set($valuebanner,"tb_banner",'bannerid='.$bannerid);
                
                }else
                {
                $valuebanner['createdate']=date("Y-m-d H:i:s");
                $valuebanner['status']=$this->post['deviceset'];
                $this->db->db_set($valuebanner,"tb_banner");
                
                
                }
                

                
                
                
                
                
                }
                }
                
                
                if(count($this->post['deletebanner']))
                {
                foreach($this->post['deletebanner'] as $valuedeletebanner)
                {
                $arraydataset['status']=0;
                $this->db->db_set($arraydataset,"tb_banner",'bannerid='.$valuedeletebanner);
                
                }
                
                
                
                
                }
                
                
                
                //$arraydataset['deviceset']=$this->post['deviceset'];
                $arraydataset=array();
                $arraydataset['bannershow']=$this->post['bannershow'];
                $this->db->db_set($arraydataset,'tb_backend_banner',' deviceset='.$this->post['deviceset']);
              
               
                $this->test();
              
              
              
              }
          
          
          
          
          }
     
     
          function testgoogle()
           {
                 require_once(pluginpath.'/simple_html_dom.php'); // uri
                $useragent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:23.0) Gecko/20100101 Firefox/23.0";
                $header = array(
                "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
                "Accept-Language: en-us,en;q=0.5",
                "Connection: keep-alive",
                "Cache-Control: no-cache",
                "Content-Type: application/x-www-form-urlencoded; charset=UTF-8",
                "Pragma: no-cache",
                );
                $ch = curl_init ("");
                curl_setopt ($ch, CURLOPT_URL, "http://www.google.co.in/search?q=ก่อนนอน%20ยาย&start=10&ie=utf-8&oe=utf-8");
                curl_setopt ($ch, CURLOPT_USERAGENT, $useragent); // set user agent
                curl_setopt($ch, CURLOPT_TIMEOUT, 3);
                curl_setopt($ch, CURLOPT_AUTOREFERER, true);
                curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
                curl_setopt($ch, CURLOPT_COOKIEJAR, "my_cookies.txt");
                curl_setopt($ch, CURLOPT_COOKIEFILE, "my_cookies.txt");
                curl_setopt($ch, CURLOPT_HEADER, 0);
                curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
                curl_setopt($ch, CURLOPT_VERBOSE, 0);
                //curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
                curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
                
                $output = curl_exec ($ch);

                curl_close($ch);
                
                
                
                
                
                $strget=str_get_html($output);
                                                echo $strget;
                exit;

                
                if(count($strget->find('#universal .web_result')))
                {
                
                        foreach($strget->find('#universal .web_result') as $element)
                        {
                            $title=strip_tags($element->find("a",0)->innertext);
                            $description=strip_tags($element->find("div",1)->innertext);
                            $link=$element->find("a",0)->href;
                            list($a,$l1)=explode("/url?q=",$link);
                            list($link,$l1)=explode("&amp;sa=",$l1);
                            
                            echo 'title--->'.$title."<br>";
                            echo 'link--->'.$link."<br>";
                            echo 'description--->'.$description."<br>";
                            echo "page ----> ".$page." <br>";
                            
                            
                            $date="";
                                                   if(strpos($description,'ชม.ก่อน ...')!==false)
                                                   {
                                                   list($hour,$t)=explode('ชม.ก่อน ...',$description);
                                                   $date=date("Y-m-d H:i:s",strtotime("-".$hour." hour"));
                                                   
                                                   }else if(strpos($description,'วันก่อน ...')!==false)
                                                   {
                                                   list($day,$t)=explode('วันก่อน ...',$description);
                                                   $date=date("Y-m-d H:i:s",strtotime("-".$day." day"));
                                                   
                                                   }else
                                                   {
                                                   echo "birdkung1";
                                                   list($date,$text)=explode('...',$description);
                                                   $arraydate=explode('...',$description);

                                                   $date=trim($date);

                                                  
                                                   list($day,$month,$year)=explode(" ",$date);
                                                   
                                                   
                                                   
                                                   
                                                  // echo $month."<br>";
                                                   //echo $month_array[$month]."<br>";
                                                   if($month_array[$month])
                                                   {
                                                  $date=$year."-".$month_array[$month].'-'.sprintf("%02d",$day).' 00:00:00';
                                                   
                                                   }else
                                                   {
                                                   $date="";
                                                   }
                                                
                                                   
                                                   
                                                   
                                                   
                                                   }
                                                   
                                                   echo 'date--->'.$date."<br>";
                                                   
                                                //   echo "--------------------------------------------------------"."<br>";
                            
                                           $arraydata2=array();
                                           $arraydata2['targetid']=$valuetarget;
                                           $arraydata2['did']=$arraydata['did'];
                                           $arraydata2['title']=$title;
                                           $arraydata2['description']=$description;
                                           $arraydata2['link']=$link;
                                           $arraydata2['page']=$page;
                                           $arraydata2['createdate']=date("Y-m-d H:i:s");
                                           if($date)$arraydata2['datedata']=$date;
                                           
                                           
                                           
                                         //  $this->db->db_set($arraydata2,"tb_subdata");       
                            
                          //  echo '---------------------------------------------------------------------'."<br>";

                        }


                }else
                {
                
                echo "test";
                
                }
                                echo $strget;
                exit;
           
                
                exit;
           
           
           }
        
        
          function bookingiddata()
          {
          if($this->post['booking_id'])
          {
          
          $arraydata['booking_id']=$this->post['booking_id'];
          if($this->post['secret_str'])$arraydata['secret_str']=$this->post['secret_str'];
          
          $sql='select * from tb_booking_code where booking_id="#'.$this->post['booking_id'].'"';
          $arraybook=$this->db->db_set_1recordrow($sql);
          if($arraybook['bookcode'])
          {
          
          
          $arraydata=$arraybook;
          
          
          }else if($this->post['secret_str'])
          {
          $this->db->db_set($arraydata,'tb_booking_code');
          
          }
          
          
          $this->arraydata['data']=$arraydata;
          
          
          
          
          
          }
          
          
          }
          
          
          function getreport()
          {
          
          
          
          
          
          }
          
          function getmygameactivity()
          {
            $arrayuser=$this->getuserbyoauth($this->userdata['oauth']);
          if($arrayuser['userid']&&$this->get['page'])
            {
            
            $page=$this->get['page'];
             $page=(($page - 1) * 10);
             $limit="limit  $page,10";
             
             
          $sql='SELECT
tb_game_activity.glogid,
tb_game_activity.`read`,
tb_game_activity.userid,
tb_game_activity.badid,
tb_game_activity.levelid,
tb_game_activity.`level`,
tb_game_activity.exp,
tb_game_activity.gxcid,
tb_game_activity.updatedate,
tb_game_activity.createdate
FROM
tb_game_activity
where tb_game_activity.userid='.$this->userdata['userid'].'
ORDER BY tb_game_activity.createdate desc '.$limit;
            $arraynewdata=array();
            $arrayact=$this->db->db_set_recordset($sql);
            $k=0;
            if(count($arrayact))
            {
            foreach($arrayact as $valueact)
            {
            if($valueact['badid']!='0')
            {
            $sql='select *

,(select tb_img.path from tb_img where tb_img.imgmid=tb_game_badge.aimgsmid) as asimg
            
             from tb_game_badge where badid='.$valueact['badid'];
            $datacheck=$this->db->db_set_1recordrow($sql);
            
            $arraynewdata['recent'][$k]['msg']='You unlocked the <em>'.$datacheck['bname'].'</em>  Badge';
            $arraynewdata['recent'][$k]['img']=baseinfo.'/'.$datacheck['asimg'];
            $arraynewdata['recent'][$k]['ago']=ago(strtotime($valueact['createdate']));
            
            }
            else if($valueact['levelid']!='0')
            {
            $sql='select *

,(select tb_img.path from tb_img where tb_img.imgmid=tb_game_level.simgmid) as simg
            
             from tb_game_level where levelid='.$valueact['levelid'];
            $datacheck=$this->db->db_set_1recordrow($sql);
            
            $arraynewdata['recent'][$k]['msg']='You reach <em>'.$datacheck['name'].'</em>.';
            $arraynewdata['recent'][$k]['img']=baseinfo.'/'.$datacheck['simg'];
            $arraynewdata['recent'][$k]['ago']=ago(strtotime($valueact['createdate']));

            
            }
            else if($valueact['level']!='0')
            {
            
            $arraynewdata['recent'][$k]['msg']='You reach <em>Level'.$valueact['level'].'</em>.';
            $textrow=sprintf("%03d",$valueact['level'] );
            $arraynewdata['recent'][$k]['img']=baseinfo.'/imglevel/lv/lv'.$textrow.'.png';
            $arraynewdata['recent'][$k]['ago']=ago(strtotime($valueact['createdate']));
            
            
            
            }
            else if($valueact['exp']!='0')
            {
            
            $sql='select name from tb_game_exp_config where gxcid='.$valueact['gxcid'];
            $datacheck=$this->db->db_set_1recordrow($sql);
            $arraynewdata['recent'][$k]['msg']='You won <em>'.$valueact['exp'].' EXP</em> by '.$datacheck['name'].'.';
            $arraynewdata['recent'][$k]['img']='';
            $arraynewdata['recent'][$k]['ago']=ago(strtotime($valueact['createdate']));
            
            }
            
            
            $k++;
            }
            
            }
            else
            {
            
            $arraynewdata['recent']=array();
            }
            
            $sql='SELECT
count(*) as rowpage
FROM
tb_game_activity
where tb_game_activity.userid='.$this->userdata['userid'].'
 ';
 $arraypage=$this->db->db_set_1recordrow($sql);
 
           $arraynewdata['rowpage']= intval($arraypage['rowpage']);
            
            
              
          $sql='SELECT
tb_game_activity.glogid,
tb_game_activity.`read`,
tb_game_activity.userid,
tb_game_activity.badid,
tb_game_activity.levelid,
tb_game_activity.`level`,
tb_game_activity.exp,
tb_game_activity.gxcid,
tb_game_activity.updatedate,
tb_game_activity.createdate
FROM
tb_game_activity
where tb_game_activity.userid='.$this->userdata['userid'].' and tb_game_activity.read=0
ORDER BY tb_game_activity.createdate desc ';
            $arraynewdata['read']=array();
            $arrayact=$this->db->db_set_recordset($sql);
            $k=0;
            if(count($arrayact))
            {
            foreach($arrayact as $valueact)
            {
            if($valueact['badid']!='0')
            {
            $sql='select *

,(select tb_img.path from tb_img where tb_img.imgmid=tb_game_badge.aimgsmid) as asimg
            
             from tb_game_badge where badid='.$valueact['badid'];
            $datacheck=$this->db->db_set_1recordrow($sql);
            
            $arraynewdata['read'][$k]['msg']='You unlocked the <em>'.$datacheck['bname'].'</em>  Badge';
            $arraynewdata['read'][$k]['img']=baseinfo.'/'.$datacheck['asimg'];
            $arraynewdata['read'][$k]['ago']=ago(strtotime($valueact['createdate']));
            $arraynewdata['read'][$k]['type']=1;
            
            }
            else if($valueact['levelid']!='0')
            {
            $sql='select *

,(select tb_img.path from tb_img where tb_img.imgmid=tb_game_level.simgmid) as simg
            
             from tb_game_level where levelid='.$valueact['levelid'];
            $datacheck=$this->db->db_set_1recordrow($sql);
            
            $arraynewdata['read'][$k]['msg']='You reach <em>'.$datacheck['name'].'</em>.';
            $arraynewdata['read'][$k]['img']=baseinfo.'/'.$datacheck['simg'];
            $arraynewdata['read'][$k]['ago']=ago(strtotime($valueact['createdate']));
            $arraynewdata['read'][$k]['type']=2;

            
            }
            else if($valueact['level']!='0')
            {
            
            $arraynewdata['read'][$k]['msg']='You reach <em>Level'.$valueact['level'].'</em>.';
            $textrow=sprintf("%03d",$valueact['level'] );
            $arraynewdata['read'][$k]['img']=baseinfo.'/imglevel/lv/level'.$textrow.'.png';
            $arraynewdata['read'][$k]['ago']=ago(strtotime($valueact['createdate']));
            $arraynewdata['read'][$k]['type']=3;
            
            
            
            }
            else if($valueact['exp']!='0')
            {
            
            $sql='select name from tb_game_exp_config where gxcid='.$valueact['gxcid'];
            $datacheck=$this->db->db_set_1recordrow($sql);
            $arraynewdata['read'][$k]['msg']='You won <em>'.$valueact['exp'].' EXP</em> by '.$datacheck['name'].'.';
            $arraynewdata['read'][$k]['img']='';
            $arraynewdata['read'][$k]['ago']=ago(strtotime($valueact['createdate']));
            $arraynewdata['read'][$k]['type']=4;
            
            }
            
            $arrayset=array();
            $arrayset['read']=1;
            $this->db->db_set($arrayset,'tb_game_activity',' glogid='.$valueact['glogid']);
            
            
            $k++;
            }
            
            }
            
            
            
            

            $this->arraydata['data']=$arraynewdata;
            
            
            }
          
          
          
          }
          
          function getallgamnification()
          {
          
            $arrayuser=$this->getuserbyoauth($this->userdata['oauth']);
            if($arrayuser['userid']&&($arrayuser['roleid']==4||$arrayuser['roleid']==3))
            {
              $this->arraydata=parent::getallgamnification();
              $this->arraydata['data']['userlist']=parent::getgameuserlist(1,$_GET['searchtext']);
            
            }
            
            
            
            
          
          
          
          }
          
          function getgameuserlist()
          {
          if($this->get['page'])
          {
          $this->arraydata['data']['userlist']=parent::getgameuserlist($this->get['page'],$this->get['searchtext']);
          }
          
          
          
          }
          
          
          
          function savegamnification()
          {
            $arrayuser=$this->getuserbyoauth($this->userdata['oauth']);
            if($arrayuser['userid']&&$this->post&&($arrayuser['roleid']==4||$arrayuser['roleid']==3))
            {
              switch ($this->post['fiter']) {
                
                case 1:
                $sql='select gexpsid from tb_game_exp_setting';
                $arrgameexp=$this->db->db_set_1recordrow($sql);
                $gexpsid=0;
                
                $arraydata['status']=$this->post['status'];
                $arraydata['exp']=$this->post['exp'];
                $arraydata['updateby']=$arrayuser['userid'];
                $arraydata['updatedate']=date("Y-m-d H:i:s");
                
                
                
                if($arrgameexp['gexpsid'])
                {
                 $gexpsid=$arrgameexp['gexpsid'];
                 $this->db->db_set($arraydata,'tb_game_exp_setting',' gexpsid='.$gexpsid);
                
                
                }
                else
                {
                
                 $arraydata['createby']=$arrayuser['userid'];
                 $arraydata['createdate']=date("Y-m-d H:i:s");
                 
                 $this->db->db_set($arraydata,'tb_game_exp_setting');
                 
                }
                
                
                
                break;
                
                case 2:
                $arraydata=array();
                if(count($this->post['level']))
                {
                foreach($this->post['level'] as $valuelevel)
                {
                $arraydata=array();
                $arraydata['exp']=$valuelevel['exp'];
                $arraydata['name']=$valuelevel['name'];
                $arraydata['imgmid']=$valuelevel['imgmid'];
                $arraydata['simgmid']=$valuelevel['simgmid'];
                $arraydata['updateby']=$arrayuser['userid'];
                $arraydata['updatedate']=date("Y-m-d H:i:s");
                if($valuelevel['levelid'])
                {
                $this->db->db_set($arraydata,'tb_game_level',' levelid='.$valuelevel['levelid']);
                
                }else
                {
                $arraydata['createdate']=date("Y-m-d H:i:s");
                $arraydata['createby']=$arrayuser['userid'];
                $this->db->db_set($arraydata,'tb_game_level');
                
                }
                
                
                }
                }
                
                 if(count($this->post['leveldelete']))
                 {
                 foreach($this->post['leveldelete'] as $valuedelete)
                 {
                 $sql='delete from tb_game_level where levelid='.$valuedelete;
                 $this->db->db_delete($sql);
                 
                 }
                 }
                
                break;
                
                case 3:
                $arraydata=array();
                if(count($this->post['badge']))
                {
                foreach($this->post['badge'] as $valuebadge)
                {
                $arraydata=array();
                $arraydata['bname']=$valuebadge['bname'];
                $arraydata['bdesc']=$valuebadge['bdesc'];
                $arraydata['gxcid']=$valuebadge['gxcid'];
                $arraydata['count']=$valuebadge['count'];
                
                $arraydata['dimgmid']=$valuebadge['dimgmid'];
                $arraydata['dsimgmid']=$valuebadge['dsimgmid'];
                
                $arraydata['aimgmid']=$valuebadge['aimgmid'];
                $arraydata['aimgsmid']=$valuebadge['aimgsmid'];
                
                $arraydata['updateby']=$arrayuser['userid'];
                $arraydata['updatedate']=date("Y-m-d H:i:s");
                
                
                 if($valuebadge['badid'])
                {
                $this->db->db_set($arraydata,'tb_game_badge',' badid='.$valuebadge['badid']);
                
                }else
                {
                $arraydata['createdate']=date("Y-m-d H:i:s");
                $arraydata['createby']=$arrayuser['userid'];
                $this->db->db_set($arraydata,'tb_game_badge');
                
                }
                
                
                }
                }
                if(count($this->post['badgedelete']))
                {
                foreach($this->post['badgedelete'] as $valuedelete)
                 {
                 
                 $sql='delete from tb_game_badge where badid='.$valuedelete;
                 $this->db->db_delete($sql);
                 
                 }
                
                
                }
                
                break;
                
                case 4:
                if(count($this->post['gameexp']))
                {
                foreach($this->post['gameexp'] as $valueexp)
                {
                if($valueexp['gxcid'])
                {
                $arraydata=array();
                $arraydata['exp']=$valueexp['exp'];
                $this->db->db_set($arraydata,'tb_game_exp_config',' gxcid='.$valueexp['gxcid']);
                
                }
                
                
                
                }
                
                }
                
                
                break;
                
                case 5:
                $sql='select gexpsid from tb_game_exp_setting';
                $arrgameexp=$this->db->db_set_1recordrow($sql);
                $arraydata['point']=$this->post['point'];
                $arraydata['updateby']=$arrayuser['userid'];
                $arraydata['updatedate']=date("Y-m-d H:i:s");
                
                 if($arrgameexp['gexpsid'])
                {
                 $gexpsid=$arrgameexp['gexpsid'];
                 $this->db->db_set($arraydata,'tb_game_exp_setting',' gexpsid='.$gexpsid);
                
                
                }else
                {
                
                 $arraydata['createby']=$arrayuser['userid'];
                 $arraydata['createdate']=date("Y-m-d H:i:s");
                 
                 $this->db->db_set($arraydata,'tb_game_exp_setting');
                }
                
                break;
                case 6:
                 if(count($this->post['gamescore']))
                {
                foreach($this->post['gamescore'] as $valuegamescore)
                {
                if($valuegamescore['userid']&&$valuegamescore['point'])
                {
                
                $arraydata['point']=$valuegamescore['point'];
                $this->db->db_set($arraydata,'tb_game_score',' userid='.$valuegamescore['userid']);
                
                }
                }
                }
                break;
                
                case 7:
                if($this->post['rimgmid']&&$this->post['rimgsmid'])
                 {
                $sql='select gexpsid from tb_game_exp_setting';
                $arrgameexp=$this->db->db_set_1recordrow($sql);
                
                $arraydata['rimgmid']=$this->post['rimgmid'];
                $arraydata['rimgsmid']=$this->post['rimgsmid'];
                $arraydata['updateby']=$arrayuser['userid'];
                $arraydata['updatedate']=date("Y-m-d H:i:s");
                 if($arrgameexp['gexpsid'])
                {
                 $gexpsid=$arrgameexp['gexpsid'];
                 $this->db->db_set($arraydata,'tb_game_exp_setting',' gexpsid='.$gexpsid);
                
                
                }else
                {
                
                 $arraydata['createby']=$arrayuser['userid'];
                 $arraydata['createdate']=date("Y-m-d H:i:s");
                 
                 $this->db->db_set($arraydata,'tb_game_exp_setting');
                 
                }
                 }
                
                break;
                
                
                

                
              }
            
            
            
            }
          
          }
          
          
          function cleanplugindata()
          {
          $k=0;
          $x=0;
                 
                 
                 $student_info['feature'][$k]['plugins'][$x]['plugid']=39;
                 $student_info['feature'][$k]['plugins'][$x]['show']=1;
                 $student_info['feature'][$k]['plugins'][$x]['icon']=0;
                 $student_info['feature'][$k]['plugins'][$x]['position']=2;
                 $student_info['feature'][$k]['plugins'][$x]['allowmobile']=1;
                
                 $student_info['feature'][$k]['plugins'][$x]['count']=0;
                 $student_info['feature'][$k]['plugins'][$x]['sort']=3;
                 $student_info['feature'][$k]['plugins'][$x]['default']=1;
                 $student_info['feature'][$k]['plugins'][$x]['alwayshow']=1;
                 $student_info['feature'][$k]['plugins'][$x]['name']="infostant";

                 
                 
                 
                 
                $data= json_encode($student_info['feature'][$k]['plugins'][$x]);
                
                $arraydata['config']=$data;
                $this->db->db_set($arraydata,'tb_plugins',' plugid='.$student_info['feature'][$k]['plugins'][$x]['plugid']);
          
          
          }
          
          function cleandataimg()
          {
          
          $sql='select other,imgmid from tb_img where other!="" and other!="false" and other like "%Model%" ';
          $dataimg=$this->db->db_set_recordset($sql);
          if(count($dataimg))
          {
          $sql="SHOW TABLES LIKE 'tb_img_setting'";
         $arraycheck=$this->db->db_set_1recordrow($sql);
         
         if(count($arraycheck)==0)
                 {
                 $sql='CREATE TABLE `tb_img_setting` (
  `imgmsid` int(11) NOT NULL AUTO_INCREMENT,
  `imgmid` int(11) NOT NULL,
  `make` varchar(200) NOT NULL,
  `model` varchar(200) NOT NULL,
  `createdate` datetime NOT NULL,
  PRIMARY KEY (`imgmsid`)
) ENGINE=InnoDB AUTO_INCREMENT=9198 DEFAULT CHARSET=utf8';
$this->db->db_set_execute($sql);
                 
                 }
         
         $arraydata=array();
          foreach($dataimg as $valueimg)
          {
          
          //echo $valueimg['other']."<br>";

         
                if(count($arraycheck))
                 {
                 $sql='select * from tb_img_setting where imgmid='.$valueimg['imgmid'];
                 $arraycheck2=$this->db->db_set_1recordrow($sql);
                 if(count($arraycheck2)==0)
                 {
                 $otherdata= json_decode($valueimg['other']);
                 $otherdata=object_to_array($otherdata);
                 
                 $arraydata['imgmid']=$valueimg['imgmid'];
                 $arraydata['make']=$otherdata['IFD0']['Make'];
                 $arraydata['model']=$otherdata['IFD0']['Model'];
                 $arraydata['createdate']=date("Y-m-d H:i:s");
                 $this->db->db_set($arraydata,'tb_img_setting');
                 
                 }
                 
                 }
         
         
         //exit;
          
          
          
          }
          
          }
          
          
          }
          
             
          function cleandataimg2()
          {
          
          $sql=' select other,tb_img.imgmid,tb_plugins_imagewidth.productid
FROM
tb_img
INNER JOIN tb_plugins_imagewidth ON tb_img.imgmid = tb_plugins_imagewidth.imgmid
where other!="" and other!="false" and other like "%Model%" ';
          $dataimg=$this->db->db_set_recordset($sql);
          if(count($dataimg))
          {
     
         
       
         
         $arraydata=array();
          foreach($dataimg as $valueimg)
          {
          
          //echo $valueimg['other']."<br>";

         
              
                 $otherdata= json_decode($valueimg['other']);
                 $arraydata['other']=object_to_array($otherdata);
                 
                 
                 
 $model='';
 if($arraydata['other']['IFD0']['Model'])
 {
 $model=$arraydata['other']['IFD0']['Model'];
 $this->savetagrelatedata($model,$valueimg['productid']);
 
 }
 
 
  $len='';
 if($arraydata['other']['EXIF'])
 {
 if($arraydata['other']['EXIF']['UndefinedTag:0xA434'])
 {
 $len=$arraydata['other']['EXIF']['UndefinedTag:0xA434'];
 $this->savetagrelatedata($len,$valueimg['productid']);
 }
 
 }
 
 
   $focus='';
 if($arraydata['other']['EXIF'])
 {
 if($arraydata['other']['EXIF']['FocalLength'])
 {
 $focus=$arraydata['other']['EXIF']['FocalLength'];
$link=str_replace('/','-',$focus);
//$focus=eval($focus).'mm';
list($d1,$d2)=explode("/",$focus);
$focus=($d1/$d2).' mm';

$this->savetagrelatedata($focus,$valueimg['productid']);
 
 }
 
 }
 
 
 
 $shutter='';
 if($arraydata['other']['EXIF'])
 {
 if($arraydata['other']['EXIF']['ISOSpeedRatings'])
 {
 $shutter='ISO'.$arraydata['other']['EXIF']['ISOSpeedRatings'];
 $this->savetagrelatedata($shutter,$valueimg['productid']);
 }
 }
 
 $aperture='';
  if($arraydata['other']['COMPUTED'])
 {
 if($arraydata['other']['COMPUTED']['ApertureFNumber'])
 {
 $aperture=$arraydata['other']['COMPUTED']['ApertureFNumber'];
 $this->savetagrelatedata($aperture,$valueimg['productid']);
 }
 }
 
 
  $exposure='';
  if($arraydata['other']['EXIF'])
 {
 if($arraydata['other']['EXIF']['ExposureTime'])
 {
 $exposure=$arraydata['other']['EXIF']['ExposureTime'];
  $this->savetagrelatedata($exposure,$valueimg['productid']);
 }
 }
 
 
   $createdate='';
  if($arraydata['other']['IFD0'])
 {
 if($arraydata['other']['IFD0']['DateTime'])
 {
 $createdate=$arraydata['other']['IFD0']['DateTime'];
 }
 }
 
 
 
 $artist='';
  if($arraydata['other']['IFD0'])
 {
 if($arraydata['other']['IFD0']['Artist'])
 {
 $artist=$arraydata['other']['IFD0']['Artist'];
 }
 }
                 
                 
                 
              //   $this->db->db_set($arraydata,'tb_img_setting');
                 
              
         
         
         //exit;
          
          
          
          }
          
          }
          
          
          }
          
          
              
          function cleandataimg3()
          {
          
          $sql=' select other,tb_img.imgmid,tb_plugins_gallery.productid
FROM
tb_img
INNER JOIN tb_plugins_gallery ON tb_img.imgmid = tb_plugins_gallery.imgmid
where other!="" and other!="false" and other like "%Model%" ';
          $dataimg=$this->db->db_set_recordset($sql);
          if(count($dataimg))
          {
     
         
       
         
         $arraydata=array();
          foreach($dataimg as $valueimg)
          {
          
          //echo $valueimg['other']."<br>";

         
              
                 $otherdata= json_decode($valueimg['other']);
                 $arraydata['other']=object_to_array($otherdata);
                 
                 
                 
 $model='';
 if($arraydata['other']['IFD0']['Model'])
 {
 $model=$arraydata['other']['IFD0']['Model'];
 $this->savetagrelatedata($model,$valueimg['productid']);
 
 }
 
 
  $len='';
 if($arraydata['other']['EXIF'])
 {
 if($arraydata['other']['EXIF']['UndefinedTag:0xA434'])
 {
 $len=$arraydata['other']['EXIF']['UndefinedTag:0xA434'];
 $this->savetagrelatedata($len,$valueimg['productid']);
 }
 
 }
 
 
   $focus='';
 if($arraydata['other']['EXIF'])
 {
 if($arraydata['other']['EXIF']['FocalLength'])
 {
 $focus=$arraydata['other']['EXIF']['FocalLength'];
$link=str_replace('/','-',$focus);
//$focus=eval($focus).'mm';
list($d1,$d2)=explode("/",$focus);
$focus=($d1/$d2).' mm';

$this->savetagrelatedata($focus,$valueimg['productid']);
 
 }
 
 }
 
 
 
 $shutter='';
 if($arraydata['other']['EXIF'])
 {
 if($arraydata['other']['EXIF']['ISOSpeedRatings'])
 {
 $shutter='ISO'.$arraydata['other']['EXIF']['ISOSpeedRatings'];
 $this->savetagrelatedata($shutter,$valueimg['productid']);
 }
 }
 
 $aperture='';
  if($arraydata['other']['COMPUTED'])
 {
 if($arraydata['other']['COMPUTED']['ApertureFNumber'])
 {
 $aperture=$arraydata['other']['COMPUTED']['ApertureFNumber'];
 $this->savetagrelatedata($aperture,$valueimg['productid']);
 }
 }
 
 
  $exposure='';
  if($arraydata['other']['EXIF'])
 {
 if($arraydata['other']['EXIF']['ExposureTime'])
 {
 $exposure=$arraydata['other']['EXIF']['ExposureTime'];
  $this->savetagrelatedata($exposure,$valueimg['productid']);
 }
 }
 
 
   $createdate='';
  if($arraydata['other']['IFD0'])
 {
 if($arraydata['other']['IFD0']['DateTime'])
 {
 $createdate=$arraydata['other']['IFD0']['DateTime'];
 }
 }
 
 
 
 $artist='';
  if($arraydata['other']['IFD0'])
 {
 if($arraydata['other']['IFD0']['Artist'])
 {
 $artist=$arraydata['other']['IFD0']['Artist'];
 }
 }
                 
                 
                 
              //   $this->db->db_set($arraydata,'tb_img_setting');
                 
              
         
         
         //exit;
          
          
          
          }
          
          }
          
          
          }
          
          
          
          function savecreatefeature()
          {
            
            
            
            $arrayuser=$this->getuserbyoauth($this->userdata['oauth']);
            if($arrayuser['userid']&&$this->post&&$arrayuser['roleid']==4)
            {
            if(count($this->post))
            {
            $k=0;
            foreach($this->post['ft_type'] as $valuepost)
            {
            $arraydata=array();
            $fid=0;
            switch ($valuepost) {
                case 1:
                 
                 if($this->post['ft_fname'][$k]&&$this->post['ft_flink'][$k]&&$this->post['ft_roleid'][$k])
                 {
                 
                 $sql="SELECT MAX(tb_feature.fid) as maxdata FROM tb_feature";
                 $datafeature=$this->db->db_set_1recordrow($sql);
                 $fid=$datafeature['maxdata']+1;
                 
                 
                 $sql="SELECT MAX(tb_feature.position) as maxdata FROM tb_feature";
                 $datafeature5=$this->db->db_set_1recordrow($sql);
                 $position=$datafeature5['maxdata']+1;
                 
                 
                 $arraydata['name']=$this->post['ft_fname'][$k];
                 $arraydata['link']=$this->post['ft_flink'][$k]; 
                 $arraydata['class']="feature";
                 $arraydata['reposize']=0;
                 $arraydata['toolbar']=1;
                 $arraydata['fid']=$fid;
                 $arraydata['ispoi']=1;
                 $arraydata['isforum']=0;
                 $arraydata['istrip']=0;
                 $arraydata['code']=0;
                 $arraydata['show']=1;
                 $arraydata['showadd']=$this->post['ft_roleid'][$k];
                 $arraydata['roleid']=$this->post['ft_roleid'][$k];
                 $arraydata['showmainplugid'][]=6;
                 $arraydata['pluginsfix'][]=6;
                 $arraydata['pluginsfix'][]=7;
                 //$student_info['feature'][$k]['showmainplugid'][]=5;
                 $arraydata['img']="";
                 
                 $arraydata2=array();
                 
                 $arraydata2['fid']=$fid;
                 $arraydata2['name']=$arraydata['name'];
                 $arraydata2['link']=$arraydata['link'];
                 $arraydata2['roleid']=$arraydata['roleid'];
                 $arraydata2['show']=$arraydata['show'];
                 $arraydata2['showadd']=$arraydata['showadd'];
                 $arraydata2['config']=json_encode($arraydata);
                 $arraydata2['position']=$position;
                 $this->db->db_set($arraydata2,'tb_feature');
                 
                 
                 if(count($this->post['ft_plugin'][$k]))
                 {
                 
                 foreach($this->post['ft_plugin'][$k] as $valueplugin)
                    {
                        if($valueplugin)
                        {
                        $sql='select * from tb_plugins where plugid='.$valueplugin;
                        $dataplugin=$this->db->db_set_1recordrow($sql);
                        
                        if($dataplugin['plugid'])
                        {
                        $arraydata3=array();
                        $arraydata3['fid']=$fid;
                        $arraydata3['plugid']=$dataplugin['plugid'];
                        $arraydata3['config']=$dataplugin['config'];
                        $this->db->db_set($arraydata3,'tb_feature_plugin');
                        }
                   
                       
                        }
                    
                    
                    }
                 
                 
                 
                 }
                 
                 
                 
                 
                 
                 
                 
                 
                 }
                 
                    break;
                case 2:
                
                    if($this->post['ft_fname'][$k]&&$this->post['ft_flink'][$k]&&$this->post['ft_roleid'][$k])
                 {
                 
                 $sql="SELECT MAX(tb_feature.fid) as maxdata FROM tb_feature";
                 $datafeature=$this->db->db_set_1recordrow($sql);
                 $fid=$datafeature['maxdata']+1;
                 
                 
                 $sql="SELECT MAX(tb_feature.position) as maxdata FROM tb_feature";
                 $datafeature5=$this->db->db_set_1recordrow($sql);
                 $position=$datafeature5['maxdata']+1;
                 
                 $arraydata['name']=$this->post['ft_fname'][$k];
                 $arraydata['link']=$this->post['ft_flink'][$k]; 
                 $arraydata['class']="feature";
                 $arraydata['reposize']=0;
                 $arraydata['toolbar']=0;
                 $arraydata['fid']=$fid;
                 $arraydata['ispoi']=0;
                 $arraydata['isforum']=0;
                 $arraydata['istrip']=1;
                 $arraydata['pageall']=3;
                 $arraydata['code']=1;
                 $arraydata['show']=1;
                 $arraydata['showadd']=$this->post['ft_roleid'][$k];
                 $arraydata['roleid']=$this->post['ft_roleid'][$k];
                 $arraydata['showmainplugid'][]=6;
                 $arraydata['pluginsfix'][]=6;
                 $arraydata['pluginsfix'][]=7;
                 //$student_info['feature'][$k]['showmainplugid'][]=5;
                 $arraydata['img']="";
                 
                 $arraydata2=array();
                 
                 $arraydata2['fid']=$fid;
                 $arraydata2['name']=$arraydata['name'];
                 $arraydata2['link']=$arraydata['link'];
                 $arraydata2['roleid']=$arraydata['roleid'];
                 $arraydata2['show']=$arraydata['show'];
                 $arraydata2['position']=$position;
                 
                 $arraydata2['showadd']=$arraydata['showadd'];
                 $arraydata2['config']=json_encode($arraydata);
                 $this->db->db_set($arraydata2,'tb_feature');
                 
                 
                 if(count($this->post['ft_plugin'][$k]))
                 {
                 
                 foreach($this->post['ft_plugin'][$k] as $valueplugin)
                    {
                        if($valueplugin)
                        {
                        $sql='select * from tb_plugins where plugid='.$valueplugin;
                        $dataplugin=$this->db->db_set_1recordrow($sql);
                        
                        if($dataplugin['plugid'])
                        {
                        $arraydata3=array();
                        $arraydata3['fid']=$fid;
                        $arraydata3['plugid']=$dataplugin['plugid'];
                        $arraydata3['config']=$dataplugin['config'];
                        $this->db->db_set($arraydata3,'tb_feature_plugin');
                        }
                   
                       
                        }
                    
                    
                    }
                 
                 
                 
                 }
                 
                 
                 
                 
                 
                 
                 
                 
                 }
                    
                    break;
                case 3:
                
                 if($this->post['ft_iframe'][$k]&&$this->post['ft_fname'][$k]&&$this->post['ft_flink'][$k])
                 {
                 $arraydata['name']=$this->post['ft_fname'][$k];
                 $arraydata['link']=$this->post['ft_flink'][$k]; 
                 $arraydata['class']="feature";
                 $arraydata['linkifame']=$this->post['ft_iframe'][$k];
                 $arraydata['isiframe']=1;
                 $arraydata['islink']=0;
                 $arraydata['istag']=0;
                 $arraydata['show']=1;
                 $arraydata['showadd']=0;
               //  $arraydata['cssadd'][]=baseinfo.'/css/theme1/booking.css';
                 $arraydata['fid']=0;
                 
                 
                 $sql="SELECT MAX(tb_feature.position) as maxdata FROM tb_feature";
                 $datafeature5=$this->db->db_set_1recordrow($sql);
                 $position=$datafeature5['maxdata']+1;
                 
                 $arraydata2=array();
                 
                 $arraydata2['fid']=0;
                 $arraydata2['name']=$arraydata['name'];
                 $arraydata2['link']=$arraydata['link'];
                 $arraydata2['roleid']=0;
                 $arraydata2['show']=$arraydata['show'];
                 $arraydata2['showadd']=$arraydata['showadd'];
                 $arraydata2['config']=json_encode($arraydata);
                 $arraydata2['position']=$position;
                 $this->db->db_set($arraydata2,'tb_feature');
                 
                 }
                    
                    break;
                case 4:
                
                if($this->post['ft_inlink'][$k]&&$this->post['ft_fname'][$k]&&$this->post['ft_flink'][$k])
                 {
                 $arraydata['name']=$this->post['ft_fname'][$k];
                 $arraydata['link']=$this->post['ft_flink'][$k]; 
                 $arraydata['class']="feature";
                 $arraydata['linkifame']=$this->post['ft_inlink'][$k];
                 $arraydata['isiframe']=0;
                 $arraydata['islink']=1;
                 $arraydata['istag']=0;
                 $arraydata['show']=1;
                 $arraydata['showadd']=0;
               //  $arraydata['cssadd'][]=baseinfo.'/css/theme1/booking.css';
                 $arraydata['fid']=0;
                 
                 $sql="SELECT MAX(tb_feature.position) as maxdata FROM tb_feature";
                 $datafeature5=$this->db->db_set_1recordrow($sql);
                 $position=$datafeature5['maxdata']+1;
                 
                 $arraydata2=array();
                 
                 $arraydata2['fid']=0;
                 $arraydata2['name']=$arraydata['name'];
                 $arraydata2['link']=$arraydata['link'];
                 $arraydata2['roleid']=0;
                 $arraydata2['show']=$arraydata['show'];
                 $arraydata2['showadd']=$arraydata['showadd'];
                 $arraydata2['config']=json_encode($arraydata);
                 $arraydata2['position']=$position;
                 $this->db->db_set($arraydata2,'tb_feature');
                 
                 }
                    
                    break;
                    
                case 5:
                
                if($this->post['ft_tag'][$k]&&$this->post['ft_fname'][$k]&&$this->post['ft_flink'][$k])
                 {
                 
                 
                 $arraydata['name']=$this->post['ft_fname'][$k];
                 $arraydata['link']=$this->post['ft_flink'][$k]; 
                 $arraydata['tag']=$this->post['ft_tag'][$k]; 
                 $arraydata['class']="feature";
                 $arraydata['linkifame']='';
                 $arraydata['isiframe']=0;
                 $arraydata['islink']=0;
                 $arraydata['istag']=1;
                 $arraydata['show']=1;
                 $arraydata['showadd']=0;
               //  $arraydata['cssadd'][]=baseinfo.'/css/theme1/booking.css';
                 $arraydata['fid']=0;
                 
                 $sql="SELECT MAX(tb_feature.position) as maxdata FROM tb_feature";
                 $datafeature5=$this->db->db_set_1recordrow($sql);
                 $position=$datafeature5['maxdata']+1;
                 
                 $arraydata2=array();
                 
                 $arraydata2['fid']=0;
                 $arraydata2['name']=$arraydata['name'];
                 $arraydata2['link']=$arraydata['link'];
                 $arraydata2['roleid']=0;
                 $arraydata2['show']=$arraydata['show'];
                 $arraydata2['showadd']=$arraydata['showadd'];
                 $arraydata2['config']=json_encode($arraydata);
                 $arraydata2['position']=$position;
                 $this->db->db_set($arraydata2,'tb_feature');
                 
                 
                 
                 
                 }
                
                    
                    break;
                    
               case 6:
                 
                 if($this->post['ft_fname'][$k]&&$this->post['ft_flink'][$k]&&$this->post['ft_roleid'][$k])
                 {
                 
                 $sql="SELECT MAX(tb_feature.fid) as maxdata FROM tb_feature";
                 $datafeature=$this->db->db_set_1recordrow($sql);
                 $fid=$datafeature['maxdata']+1;
                 
                 
                 $sql="SELECT MAX(tb_feature.position) as maxdata FROM tb_feature";
                 $datafeature5=$this->db->db_set_1recordrow($sql);
                 $position=$datafeature5['maxdata']+1;
                 
                 
                 $arraydata['name']=$this->post['ft_fname'][$k];
                 $arraydata['link']=$this->post['ft_flink'][$k]; 
                 $arraydata['class']="feature";
                 $arraydata['reposize']=0;
                 $arraydata['toolbar']=1;
                 $arraydata['fid']=$fid;
                 $arraydata['ispoi']=0;
                 $arraydata['isforum']=1;
                 $arraydata['istrip']=0;
                 $arraydata['code']=0;
                 $arraydata['show']=1;
                 $arraydata['showadd']=$this->post['ft_roleid'][$k];
                 $arraydata['roleid']=$this->post['ft_roleid'][$k];
                 $arraydata['showmainplugid'][]=6;
                 $arraydata['pluginsfix'][]=6;
                 $arraydata['pluginsfix'][]=7;
                 //$student_info['feature'][$k]['showmainplugid'][]=5;
                 $arraydata['img']="";
                 
                 $arraydata2=array();
                 
                 $arraydata2['fid']=$fid;
                 $arraydata2['name']=$arraydata['name'];
                 $arraydata2['link']=$arraydata['link'];
                 $arraydata2['roleid']=$arraydata['roleid'];
                 $arraydata2['show']=$arraydata['show'];
                 $arraydata2['showadd']=$arraydata['showadd'];
                 $arraydata2['config']=json_encode($arraydata);
                 $arraydata2['position']=$position;
                 $this->db->db_set($arraydata2,'tb_feature');
                 
                 
                 if(count($this->post['ft_plugin'][$k]))
                 {
                 
                 foreach($this->post['ft_plugin'][$k] as $valueplugin)
                    {
                        if($valueplugin)
                        {
                        $sql='select * from tb_plugins where plugid='.$valueplugin;
                        $dataplugin=$this->db->db_set_1recordrow($sql);
                        
                        if($dataplugin['plugid'])
                        {
                        $arraydata3=array();
                        $arraydata3['fid']=$fid;
                        $arraydata3['plugid']=$dataplugin['plugid'];
                        $arraydata3['config']=$dataplugin['config'];
                        $this->db->db_set($arraydata3,'tb_feature_plugin');
                        }
                   
                       
                        }
                    
                    
                    }
                 
                 
                 
                 }
                 
                 
                 
                 
                 
                 
                 
                 
                 }
                 
                    break;
                    
               case 8:
                
                    if($this->post['ft_fname'][$k]&&$this->post['ft_flink'][$k]&&$this->post['ft_roleid'][$k])
                 {
                 
                 $sql="SELECT MAX(tb_feature.fid) as maxdata FROM tb_feature";
                 $datafeature=$this->db->db_set_1recordrow($sql);
                 $fid=$datafeature['maxdata']+1;
                 
                 
                 $sql="SELECT MAX(tb_feature.position) as maxdata FROM tb_feature";
                 $datafeature5=$this->db->db_set_1recordrow($sql);
                 $position=$datafeature5['maxdata']+1;
                 
                 $arraydata['name']=$this->post['ft_fname'][$k];
                 $arraydata['link']=$this->post['ft_flink'][$k]; 
                 $arraydata['class']="feature";
                 $arraydata['reposize']=0;
                 $arraydata['toolbar']=0;
                 $arraydata['fid']=$fid;
                 $arraydata['ispoi']=0;
                 $arraydata['isforum']=0;
                 $arraydata['istrip']=0;
                 $arraydata['isinfo']=1;
                 $arraydata['pageall']=3;
                 $arraydata['code']=1;
                 $arraydata['show']=1;
                 $arraydata['showadd']=$this->post['ft_roleid'][$k];
                 $arraydata['roleid']=$this->post['ft_roleid'][$k];
                 $arraydata['showmainplugid'][]=6;
                 $arraydata['pluginsfix'][]=6;
                 $arraydata['pluginsfix'][]=7;
                 //$student_info['feature'][$k]['showmainplugid'][]=5;
                 $arraydata['img']="";
                 
                 $arraydata2=array();
                 
                 $arraydata2['fid']=$fid;
                 $arraydata2['name']=$arraydata['name'];
                 $arraydata2['link']=$arraydata['link'];
                 $arraydata2['roleid']=$arraydata['roleid'];
                 $arraydata2['show']=$arraydata['show'];
                 $arraydata2['position']=$position;
                 
                 $arraydata2['showadd']=$arraydata['showadd'];
                 $arraydata2['config']=json_encode($arraydata);
                 $this->db->db_set($arraydata2,'tb_feature');
                 
                 
                 if(count($this->post['ft_plugin'][$k]))
                 {
                 
                 foreach($this->post['ft_plugin'][$k] as $valueplugin)
                    {
                        if($valueplugin)
                        {
                        $sql='select * from tb_plugins where plugid='.$valueplugin;
                        $dataplugin=$this->db->db_set_1recordrow($sql);
                        
                        if($dataplugin['plugid'])
                        {
                        $arraydata3=array();
                        $arraydata3['fid']=$fid;
                        $arraydata3['plugid']=$dataplugin['plugid'];
                        $arraydata3['config']=$dataplugin['config'];
                        $this->db->db_set($arraydata3,'tb_feature_plugin');
                        }
                   
                       
                        }
                    
                    
                    }
                 
                 
                 
                 }
                 
                 
                 
                 
                 
                 
                 
                 
                 }
                    
                    break;     
                    
               
            }
            
            
            
            if($fid)
            {
            $arraytag=array();
            
            if(count($this->post['ft_sytag'][$k]))
            {
            foreach($this->post['ft_sytag'][$k] as $valuetag)
            {
            $valuetag= trim($valuetag);
            if($valuetag)
            {
            
            $sql="select tagid from tb_tag where tb_tag.name='".$valuetag."'";
            $datatag=$this->db->db_set_1recordrow($sql);
            if($datatag['tagid'])
            {
            $sql='select stagid from tb_tag_show where tb_tag_show.tagid='.$datatag['tagid'].' and tb_tag_show.fid='.$fid;
            $datatagre=$this->db->db_set_1recordrow($sql);
            if(!$datatagre['stagid'])
            {
            $arraytagre=array();
            $arraytagre['fid']=$fid;
            $arraytagre['tagid']=$datatag['tagid'];
            $this->db->db_set($arraytagre,'tb_tag_show');
            
            }
            
            }else
            {
            
            $arraytag2=array();
            $arraytag2['name']=$valuetag;
            $arraytag2['all']=0;
            $arraytag2['system']=1;
            $arraytag2['fid']=$fid;
            $arraytag2['createby']=$arrayuser['userid'];
            $arraytag2['createdate']=date("Y-m-d H:i:s");
            
            $this->db->db_set($arraytag2,'tb_tag');
            $tagid=$this->db->db_get_last_number();
            $arraytagre=array();
            $arraytagre['fid']=$fid;
            $arraytagre['tagid']=$tagid;
            $this->db->db_set($arraytagre,'tb_tag_show');
            
            
            }
            
            
            
            }
            
            
            
            }
            
            
            
            }
            
            
            
            
            
            }
            
            
            $k++;
            
            
            
            
            
            
            
            
            }
            
            
            $this->test();
            
            }
            
            
            
            }
          
          
          }
          
          function savefeaturemanager()
          {

            $arrayuser=$this->getuserbyoauth($this->userdata['oauth']);
            if($arrayuser['userid']&&$this->post&&($arrayuser['roleid']==3||$arrayuser['roleid']==4))
            {
            if(count($this->post))
            {
            $k=0;
            foreach($this->post['ft_type'] as $valuepost)
            {
            $arraydata=array();
            $fid=0;
            switch ($valuepost) {
                case 1:
                 
                 if($this->post['ft_fname'][$k]&&$this->post['ft_flink'][$k]&&$this->post['ft_roleid'][$k]&&$this->post['ft_fsid'][$k]&&$this->post['ft_fid'][$k])
                 {
                 
           //      $sql="SELECT MAX(tb_feature.fid) as maxdata FROM tb_feature";
            //     $datafeature=$this->db->db_set_1recordrow($sql);
                 $fid=$this->post['ft_fid'][$k];
                 
                 
               //  $sql="SELECT MAX(tb_feature.position) as maxdata FROM tb_feature";
             //    $datafeature5=$this->db->db_set_1recordrow($sql);
                 $position=$this->post['ft_order'][$k];
                 
                 
                 $arraydata['name']=$this->post['ft_fname'][$k];
                 $arraydata['link']=$this->post['ft_flink'][$k]; 
                 $arraydata['class']="feature";
                 $arraydata['reposize']=0;
                 $arraydata['toolbar']=1;
                 $arraydata['fid']=$this->post['ft_fid'][$k];
                 $arraydata['ispoi']=1;
                 $arraydata['istrip']=0;
                 $arraydata['isforum']=0;
                 $arraydata['code']=0;
                 $arraydata['show']=1;
                 $arraydata['showadd']=0;
                 $arraydata['showwrite']=$this->post['ft_roleid'][$k];
                 $arrayread=$this->post['ft_roleidread'][$k];
                 if($arrayread&&count($arrayread))
                 {
                 
                 }else
                 {
                 $arrayread=array();
                 }
                 
                 $arraydata['showread']=$arrayread;
                 $arraydata['roleid']=0;
                 
                 $arraydata['showmainplugid'][]=6;
                 $arraydata['pluginsfix'][]=6;
                 $arraydata['pluginsfix'][]=7;
                 //$student_info['feature'][$k]['showmainplugid'][]=5;
                 $arraydata['img']="";
                 
                 $arraydata2=array();
                 
                 $arraydata2['fid']=$fid;
                 $arraydata2['name']=$arraydata['name'];
                 $arraydata2['link']=$arraydata['link'];
                 $arraydata2['roleid']=0;
                 $arraydata2['show']=1;
                 $arraydata2['showadd']=0;
                 $arraydata2['config']=json_encode($arraydata);
                 $arraydata2['position']=$position;
                 $this->db->db_set($arraydata2,'tb_feature',' fsid='.$this->post['ft_fsid'][$k]);
                 
                  
                 //$sql="delete  from tb_plugins";
                 
                // $sql="";
                 
                 
                 if(count($this->post['ft_plugin'][$k]))
                 {
                 
                 $sql='select * from tb_feature_plugin where fid='.$this->post['ft_fid'][$k];
                 $datapluginall=$this->db->db_set_recordset($sql);
                 $arraydatadelete=array();
                 if(count($datapluginall))
                 {
                 foreach($datapluginall as $valuepluginall)
                 {
                 
              
                 if(in_array($valuepluginall['plugid'],$this->post['ft_plugin'][$k]))
                 {
                 
                 
                 
                 }else
                 {
                 $arraydatadelete[]=$valuepluginall['fplugin'];
                 
                 }
                 
                 
                 }
                 
                 }
                 
                 

                 
                 
                 
                 foreach($this->post['ft_plugin'][$k] as $valueplugin)
                    {
                    
                        
                        if($valueplugin)
                        {
                        
                        $sql='select * from tb_feature_plugin where fid='.$this->post['ft_fid'][$k].' and plugid='.$valueplugin;
                        $dataplugincheck=$this->db->db_set_1recordrow($sql);
                        if($dataplugincheck['fplugin'])
                        {
                        
                        
                        
                        
                        }else
                        {
                        
                        
                        
                        $sql='select * from tb_plugins where plugid='.$valueplugin;
                        $dataplugin=$this->db->db_set_1recordrow($sql);
                        
                        if($dataplugin['plugid'])
                        {
                        $arraydata3=array();
                        $arraydata3['fid']=$fid;
                        $arraydata3['plugid']=$dataplugin['plugid'];
                        $arraydata3['config']=$dataplugin['config'];
                        $this->db->db_set($arraydata3,'tb_feature_plugin');
                        }
                        
                        }
                   
                       
                        }
                    
                    
                    }
                    
                    if(count($arraydatadelete))
                    {
                    foreach($arraydatadelete as $fvalueplugin)
                    {
                    if($fvalueplugin)
                    {
                    $sql="delete from tb_feature_plugin where fplugin=".$fvalueplugin;
                    $this->db->db_set_execute($sql);
                    }
                    
                    
                    
                    }
                    
                    
                    }
                 
                 
                 
                 }
                 
                 
                 
                 
                 
                 
                 
                 
                 }
                 
                    break;
                case 2:
                
                    if($this->post['ft_fname'][$k]&&$this->post['ft_flink'][$k]&&$this->post['ft_roleid'][$k]&&$this->post['ft_fsid'][$k]&&$this->post['ft_fid'][$k])
                 {
                 
           //      $sql="SELECT MAX(tb_feature.fid) as maxdata FROM tb_feature";
            //     $datafeature=$this->db->db_set_1recordrow($sql);
                 $fid=$this->post['ft_fid'][$k];
                 
                 
               //  $sql="SELECT MAX(tb_feature.position) as maxdata FROM tb_feature";
             //    $datafeature5=$this->db->db_set_1recordrow($sql);
                 $position=$this->post['ft_order'][$k];
                 
                 
                 $arraydata['name']=$this->post['ft_fname'][$k];
                 $arraydata['link']=$this->post['ft_flink'][$k]; 
                 $arraydata['class']="feature";
                 $arraydata['reposize']=0;
                 $arraydata['toolbar']=1;
                 $arraydata['fid']=$this->post['ft_fid'][$k];
                 $arraydata['ispoi']=0;
                 $arraydata['istrip']=1;
                 $arraydata['isforum']=0;
                 $arraydata['code']=1;
                 $arraydata['pageall']=3;
                 
                 $arraydata['show']=1;
                 
                 $arraydata['showadd']=0;
                 $arraydata['showwrite']=$this->post['ft_roleid'][$k];
                  $arrayread=$this->post['ft_roleidread'][$k];
                 if($arrayread&&count($arrayread))
                 {
                 
                 }else
                 {
                 $arrayread=array();
                 }
                 
                 $arraydata['showread']=$arrayread;
                 $arraydata['roleid']=0;
                 
                 $arraydata['showmainplugid'][]=6;
                 $arraydata['pluginsfix'][]=6;
                 $arraydata['pluginsfix'][]=7;
                 //$student_info['feature'][$k]['showmainplugid'][]=5;
                 $arraydata['img']="";
                 
                 $arraydata2=array();
                 
                 $arraydata2['fid']=$fid;
                 $arraydata2['name']=$arraydata['name'];
                 $arraydata2['link']=$arraydata['link'];
                 $arraydata2['roleid']=0;
                 $arraydata2['show']=1;
                 $arraydata2['showadd']=0;
                 $arraydata2['config']=json_encode($arraydata);
                 $arraydata2['position']=$position;
                 $this->db->db_set($arraydata2,'tb_feature',' fsid='.$this->post['ft_fsid'][$k]);
                 
                  
                 //$sql="delete  from tb_plugins";
                 
                // $sql="";
                 
                 
                 if(count($this->post['ft_plugin'][$k]))
                 {
                 
                 $sql='select * from tb_feature_plugin where fid='.$this->post['ft_fid'][$k];
                 $datapluginall=$this->db->db_set_recordset($sql);
                 $arraydatadelete=array();
                 if(count($datapluginall))
                 {
                 foreach($datapluginall as $valuepluginall)
                 {
                 
              
                 if(in_array($valuepluginall['plugid'],$this->post['ft_plugin'][$k]))
                 {
                 
                 
                 
                 }else
                 {
                 $arraydatadelete[]=$valuepluginall['fplugin'];
                 
                 }
                 
                 
                 }
                 
                 }
                 
                 

                 
                 
                 
                 foreach($this->post['ft_plugin'][$k] as $valueplugin)
                    {
                    
                        
                        if($valueplugin)
                        {
                        
                        $sql='select * from tb_feature_plugin where fid='.$this->post['ft_fid'][$k].' and plugid='.$valueplugin;
                        $dataplugincheck=$this->db->db_set_1recordrow($sql);
                        if($dataplugincheck['fplugin'])
                        {
                        
                        
                        
                        
                        }else
                        {
                        
                        
                        
                        $sql='select * from tb_plugins where plugid='.$valueplugin;
                        $dataplugin=$this->db->db_set_1recordrow($sql);
                        
                        if($dataplugin['plugid'])
                        {
                        $arraydata3=array();
                        $arraydata3['fid']=$fid;
                        $arraydata3['plugid']=$dataplugin['plugid'];
                        $arraydata3['config']=$dataplugin['config'];
                        $this->db->db_set($arraydata3,'tb_feature_plugin');
                        }
                        
                        }
                   
                       
                        }
                    
                    
                    }
                    
                    if(count($arraydatadelete))
                    {
                    foreach($arraydatadelete as $fvalueplugin)
                    {
                    if($fvalueplugin)
                    {
                    $sql="delete from tb_feature_plugin where fplugin=".$fvalueplugin;
                    $this->db->db_set_execute($sql);
                    }
                    
                    
                    
                    }
                    
                    
                    }
                 
                 
                 
                 }
                 
                 
                 
                 
                 
                 
                 
                 
                 }
                    
                    break;
                case 3:
                
                 if($this->post['ft_iframe'][$k]&&$this->post['ft_fname'][$k]&&$this->post['ft_flink'][$k]&&$this->post['ft_fsid'][$k]&&($this->post['ft_fid'][$k]==0))
                 {
                 $arraydata['name']=$this->post['ft_fname'][$k];
                 $arraydata['link']=$this->post['ft_flink'][$k]; 
                 $arraydata['class']="feature";
                 $arraydata['linkifame']=$this->post['ft_iframe'][$k];
                 $arraydata['isiframe']=1;
                 $arraydata['islink']=0;
                 $arraydata['istag']=0;
                 $arraydata['showadd']=0;
                 
                 $arraydata['showwrite']=$this->post['ft_roleid'][$k];
                  $arrayread=$this->post['ft_roleidread'][$k];
                 if($arrayread&&count($arrayread))
                 {
                 
                 }else
                 {
                 $arrayread=array();
                 }
                 
                 $arraydata['showread']=$arrayread;
                 $arraydata['roleid']=0;
                 $arraydata['show']=1;
               //  $arraydata['cssadd'][]=baseinfo.'/css/theme1/booking.css';
                 $arraydata['fid']=0;
                 
                 
                 
                 $position=$this->post['ft_order'][$k];;
                 
                 $arraydata2=array();
                 
                 $arraydata2['fid']=0;
                 $arraydata2['name']=$arraydata['name'];
                 $arraydata2['link']=$arraydata['link'];
                 $arraydata2['roleid']=0;
                 $arraydata2['show']=1;
                 $arraydata2['showadd']=0;
                 $arraydata2['config']=json_encode($arraydata);
                 $arraydata2['position']=$position;
                 $this->db->db_set($arraydata2,'tb_feature',' fsid='.$this->post['ft_fsid'][$k]);
                 
                 }
                    
                    break;
                case 4:
                
                if($this->post['ft_inlink'][$k]&&$this->post['ft_fname'][$k]&&$this->post['ft_flink'][$k]&&$this->post['ft_fsid'][$k]&&($this->post['ft_fid'][$k]==0))
                 {
                 $arraydata['name']=$this->post['ft_fname'][$k];
                 $arraydata['link']=$this->post['ft_flink'][$k]; 
                 $arraydata['class']="feature";
                 $arraydata['linkifame']=$this->post['ft_inlink'][$k];
                 $arraydata['isiframe']=0;
                 $arraydata['islink']=1;
                 $arraydata['istag']=0;
                 $arraydata['show']=1;
                 $arraydata['showadd']=0;
                 $arraydata['showwrite']=$this->post['ft_roleid'][$k];
                  $arrayread=$this->post['ft_roleidread'][$k];
                 if($arrayread&&count($arrayread))
                 {
                 
                 }else
                 {
                 $arrayread=array();
                 }
                 
                 $arraydata['showread']=$arrayread;
                 $arraydata['roleid']=0;
               //  $arraydata['cssadd'][]=baseinfo.'/css/theme1/booking.css';
                 $arraydata['fid']=0;
                 
                 $position=$this->post['ft_order'][$k];;
                 
                 $arraydata2=array();
                 
                 $arraydata2['fid']=0;
                 $arraydata2['name']=$arraydata['name'];
                 $arraydata2['link']=$arraydata['link'];

                 $arraydata2['roleid']=0;
                 $arraydata2['show']=1;
                 $arraydata2['showadd']=0;
                 
                 $arraydata2['config']=json_encode($arraydata);
                 $arraydata2['position']=$position;
                 $this->db->db_set($arraydata2,'tb_feature',' fsid='.$this->post['ft_fsid'][$k]);
                 
                 }
                    
                    break;
                    
                case 5:
                
                if($this->post['ft_tag'][$k]&&$this->post['ft_fname'][$k]&&$this->post['ft_flink'][$k]&&$this->post['ft_fsid'][$k]&&($this->post['ft_fid'][$k]==0))
                 {
                 
                 
                 $arraydata['name']=$this->post['ft_fname'][$k];
                 $arraydata['link']=$this->post['ft_flink'][$k]; 
                 $arraydata['tag']=$this->post['ft_tag'][$k]; 
                 $arraydata['class']="feature";
                 $arraydata['linkifame']='';
                 $arraydata['isiframe']=0;
                 $arraydata['islink']=0;
                 $arraydata['istag']=1;
                 $arraydata['show']=1;
                 $arraydata['showadd']=0;
                 $arraydata['showwrite']=$this->post['ft_roleid'][$k];
                  $arrayread=$this->post['ft_roleidread'][$k];
                 if($arrayread&&count($arrayread))
                 {
                 
                 }else
                 {
                 $arrayread=array();
                 }
                 
                 $arraydata['showread']=$arrayread;
                 $arraydata['roleid']=0;
               //  $arraydata['cssadd'][]=baseinfo.'/css/theme1/booking.css';
                 $arraydata['fid']=0;
                 
                 $position=$this->post['ft_order'][$k];
                 
                 $arraydata2=array();
                 
                 $arraydata2['fid']=0;
                 $arraydata2['name']=$arraydata['name'];
                 $arraydata2['link']=$arraydata['link'];
                 $arraydata2['roleid']=0;
                 $arraydata2['show']=1;
                 $arraydata2['showadd']=0;
                 $arraydata2['config']=json_encode($arraydata);
                 $arraydata2['position']=$position;
                $this->db->db_set($arraydata2,'tb_feature',' fsid='.$this->post['ft_fsid'][$k]);
                 
                 
                 
                 
                 }
                
                    
                    break;
                 case 6:   
                    if($this->post['ft_fname'][$k]&&$this->post['ft_flink'][$k]&&$this->post['ft_roleid'][$k]&&$this->post['ft_fsid'][$k]&&$this->post['ft_fid'][$k])
                 {
                 
           //      $sql="SELECT MAX(tb_feature.fid) as maxdata FROM tb_feature";
            //     $datafeature=$this->db->db_set_1recordrow($sql);
                 $fid=$this->post['ft_fid'][$k];
                 
                 
               //  $sql="SELECT MAX(tb_feature.position) as maxdata FROM tb_feature";
             //    $datafeature5=$this->db->db_set_1recordrow($sql);
                 $position=$this->post['ft_order'][$k];
                 
                 
                 $arraydata['name']=$this->post['ft_fname'][$k];
                 $arraydata['link']=$this->post['ft_flink'][$k]; 
                 $arraydata['class']="feature";
                 $arraydata['reposize']=0;
                 $arraydata['toolbar']=1;
                 $arraydata['fid']=$this->post['ft_fid'][$k];
                 $arraydata['ispoi']=0;
                 $arraydata['istrip']=0;
                 $arraydata['isforum']=1;
                 $arraydata['code']=0;
                 $arraydata['showadd']=0;
                 $arraydata['showwrite']=$this->post['ft_roleid'][$k];
                  $arrayread=$this->post['ft_roleidread'][$k];
                 if($arrayread&&count($arrayread))
                 {
                 
                 }else
                 {
                 $arrayread=array();
                 }
                 
                 $arraydata['showread']=$arrayread;
                 $arraydata['roleid']=0;
                 $arraydata['show']=1;
                 $arraydata['showmainplugid'][]=6;
                 $arraydata['pluginsfix'][]=6;
                 $arraydata['pluginsfix'][]=7;
                 //$student_info['feature'][$k]['showmainplugid'][]=5;
                 $arraydata['img']="";
                 
                 $arraydata2=array();
                 
                 $arraydata2['fid']=$fid;
                 $arraydata2['name']=$arraydata['name'];
                 $arraydata2['link']=$arraydata['link'];
                 $arraydata2['roleid']=0;
                 $arraydata2['show']=1;
                 $arraydata2['showadd']=0;
                 $arraydata2['config']=json_encode($arraydata);
                 $arraydata2['position']=$position;
                 $this->db->db_set($arraydata2,'tb_feature',' fsid='.$this->post['ft_fsid'][$k]);
                 
                  
                 //$sql="delete  from tb_plugins";
                 
                // $sql="";
                 
                 
                 if(count($this->post['ft_plugin'][$k]))
                 {
                 
                 $sql='select * from tb_feature_plugin where fid='.$this->post['ft_fid'][$k];
                 $datapluginall=$this->db->db_set_recordset($sql);
                 $arraydatadelete=array();
                 if(count($datapluginall))
                 {
                 foreach($datapluginall as $valuepluginall)
                 {
                 
              
                 if(in_array($valuepluginall['plugid'],$this->post['ft_plugin'][$k]))
                 {
                 
                 
                 
                 }else
                 {
                 $arraydatadelete[]=$valuepluginall['fplugin'];
                 
                 }
                 
                 
                 }
                 
                 }
                 
                 

                 
                 
                 
                 foreach($this->post['ft_plugin'][$k] as $valueplugin)
                    {
                    
                        
                        if($valueplugin)
                        {
                        
                        $sql='select * from tb_feature_plugin where fid='.$this->post['ft_fid'][$k].' and plugid='.$valueplugin;
                        $dataplugincheck=$this->db->db_set_1recordrow($sql);
                        if($dataplugincheck['fplugin'])
                        {
                        
                        
                        
                        
                        }else
                        {
                        
                        
                        
                        $sql='select * from tb_plugins where plugid='.$valueplugin;
                        $dataplugin=$this->db->db_set_1recordrow($sql);
                        
                        if($dataplugin['plugid'])
                        {
                        $arraydata3=array();
                        $arraydata3['fid']=$fid;
                        $arraydata3['plugid']=$dataplugin['plugid'];
                        $arraydata3['config']=$dataplugin['config'];
                        $this->db->db_set($arraydata3,'tb_feature_plugin');
                        }
                        
                        }
                   
                       
                        }
                    
                    
                    }
                    
                    if(count($arraydatadelete))
                    {
                    foreach($arraydatadelete as $fvalueplugin)
                    {
                    if($fvalueplugin)
                    {
                    $sql="delete from tb_feature_plugin where fplugin=".$fvalueplugin;
                    $this->db->db_set_execute($sql);
                    }
                    
                    
                    
                    }
                    
                    
                    }
                 
                 
                 
                 }
                 
                 
                 
                 
                 
                 
                 
                 
                 }
                 
                    break;
                 
                 case 7:
                 
                 if($this->post['ft_fname'][$k]&&$this->post['ft_flink'][$k]&&$this->post['ft_roleid'][$k]&&$this->post['ft_fsid'][$k]&&$this->post['ft_fid'][$k])
                 {
                 
           //      $sql="SELECT MAX(tb_feature.fid) as maxdata FROM tb_feature";
            //     $datafeature=$this->db->db_set_1recordrow($sql);
                 $fid=$this->post['ft_fid'][$k];
                 
                 
               //  $sql="SELECT MAX(tb_feature.position) as maxdata FROM tb_feature";
             //    $datafeature5=$this->db->db_set_1recordrow($sql);
                 $position=$this->post['ft_order'][$k];
                 
                 
                 $arraydata['name']=$this->post['ft_fname'][$k];
                 $arraydata['link']=$this->post['ft_flink'][$k]; 
                 $arraydata['class']=$this->post['ft_custom'][$k]; 
                 $arraydata['reposize']=0;
                 $arraydata['toolbar']=1;
                 $arraydata['fid']=$this->post['ft_fid'][$k];
                 $arraydata['ispoi']=0;
                 $arraydata['istrip']=0;
                 $arraydata['iscustom']=1;
                 $arraydata['isforum']=0;
                 $arraydata['code']=0;
                 $arraydata['show']=1;
                 $arraydata['showadd']=0;
                 $arraydata['showwrite']=$this->post['ft_roleid'][$k];
                 $arrayread=$this->post['ft_roleidread'][$k];
                 if($arrayread&&count($arrayread))
                 {
                 
                 }else
                 {
                 $arrayread=array();
                 }
                 
                 $arraydata['showread']=$arrayread;
                 $arraydata['roleid']=0;
                 
                 $arraydata['showmainplugid'][]=6;
                 $arraydata['pluginsfix'][]=6;
                 $arraydata['pluginsfix'][]=7;
                 //$student_info['feature'][$k]['showmainplugid'][]=5;
                 $arraydata['img']="";
                 
                 $arraydata2=array();
                 
                 $arraydata2['fid']=$fid;
                 $arraydata2['name']=$arraydata['name'];
                 $arraydata2['link']=$arraydata['link'];
                 $arraydata2['roleid']=0;
                 $arraydata2['show']=1;
                 $arraydata2['showadd']=0;
                 $arraydata2['config']=json_encode($arraydata);
                 $arraydata2['position']=$position;
                 $this->db->db_set($arraydata2,'tb_feature',' fsid='.$this->post['ft_fsid'][$k]);
                 
                  
                 //$sql="delete  from tb_plugins";
                 
                // $sql="";
                 
                 
                 if(count($this->post['ft_plugin'][$k]))
                 {
                 
                 $sql='select * from tb_feature_plugin where fid='.$this->post['ft_fid'][$k];
                 $datapluginall=$this->db->db_set_recordset($sql);
                 $arraydatadelete=array();
                 if(count($datapluginall))
                 {
                 foreach($datapluginall as $valuepluginall)
                 {
                 
              
                 if(in_array($valuepluginall['plugid'],$this->post['ft_plugin'][$k]))
                 {
                 
                 
                 
                 }else
                 {
                 $arraydatadelete[]=$valuepluginall['fplugin'];
                 
                 }
                 
                 
                 }
                 
                 }
                 
                 

                 
                 
                 
                 foreach($this->post['ft_plugin'][$k] as $valueplugin)
                    {
                    
                        
                        if($valueplugin)
                        {
                        
                        $sql='select * from tb_feature_plugin where fid='.$this->post['ft_fid'][$k].' and plugid='.$valueplugin;
                        $dataplugincheck=$this->db->db_set_1recordrow($sql);
                        if($dataplugincheck['fplugin'])
                        {
                        
                        
                        
                        
                        }else
                        {
                        
                        
                        
                        $sql='select * from tb_plugins where plugid='.$valueplugin;
                        $dataplugin=$this->db->db_set_1recordrow($sql);
                        
                        if($dataplugin['plugid'])
                        {
                        $arraydata3=array();
                        $arraydata3['fid']=$fid;
                        $arraydata3['plugid']=$dataplugin['plugid'];
                        $arraydata3['config']=$dataplugin['config'];
                        $this->db->db_set($arraydata3,'tb_feature_plugin');
                        }
                        
                        }
                   
                       
                        }
                    
                    
                    }
                    
                    if(count($arraydatadelete))
                    {
                    foreach($arraydatadelete as $fvalueplugin)
                    {
                    if($fvalueplugin)
                    {
                    $sql="delete from tb_feature_plugin where fplugin=".$fvalueplugin;
                    $this->db->db_set_execute($sql);
                    }
                    
                    
                    
                    }
                    
                    
                    }
                 
                 
                 
                 }
                 
                 
                 
                 
                 
                 
                 
                 
                 }
                 
                    break;  
                    
                case 8:
                
                    if($this->post['ft_fname'][$k]&&$this->post['ft_flink'][$k]&&$this->post['ft_roleid'][$k]&&$this->post['ft_fsid'][$k]&&$this->post['ft_fid'][$k])
                 {
                 
           //      $sql="SELECT MAX(tb_feature.fid) as maxdata FROM tb_feature";
            //     $datafeature=$this->db->db_set_1recordrow($sql);
                 $fid=$this->post['ft_fid'][$k];
                 
                 
               //  $sql="SELECT MAX(tb_feature.position) as maxdata FROM tb_feature";
             //    $datafeature5=$this->db->db_set_1recordrow($sql);
                 $position=$this->post['ft_order'][$k];
                 
                 
                 $arraydata['name']=$this->post['ft_fname'][$k];
                 $arraydata['link']=$this->post['ft_flink'][$k]; 
                 $arraydata['class']="feature";
                 $arraydata['reposize']=0;
                 $arraydata['toolbar']=1;
                 $arraydata['fid']=$this->post['ft_fid'][$k];
                 $arraydata['ispoi']=0;
                 $arraydata['istrip']=0;
                 $arraydata['isinfo']=1;
                 $arraydata['isforum']=0;
                 $arraydata['code']=1;
                 $arraydata['pageall']=3;
                 
                 $arraydata['show']=1;
                 
                 $arraydata['showadd']=0;
                 $arraydata['showwrite']=$this->post['ft_roleid'][$k];
                  $arrayread=$this->post['ft_roleidread'][$k];
                 if($arrayread&&count($arrayread))
                 {
                 
                 }else
                 {
                 $arrayread=array();
                 }
                 
                 $arraydata['showread']=$arrayread;
                 $arraydata['roleid']=0;
                 
                 $arraydata['showmainplugid'][]=6;
                 $arraydata['pluginsfix'][]=6;
                 $arraydata['pluginsfix'][]=7;
                 //$student_info['feature'][$k]['showmainplugid'][]=5;
                 $arraydata['img']="";
                 
                 $arraydata2=array();
                 
                 $arraydata2['fid']=$fid;
                 $arraydata2['name']=$arraydata['name'];
                 $arraydata2['link']=$arraydata['link'];
                 $arraydata2['roleid']=0;
                 $arraydata2['show']=1;
                 $arraydata2['showadd']=0;
                 $arraydata2['config']=json_encode($arraydata);
                 $arraydata2['position']=$position;
                 $this->db->db_set($arraydata2,'tb_feature',' fsid='.$this->post['ft_fsid'][$k]);
                 
                  
                 //$sql="delete  from tb_plugins";
                 
                // $sql="";
                 
                 
                 if(count($this->post['ft_plugin'][$k]))
                 {
                 
                 $sql='select * from tb_feature_plugin where fid='.$this->post['ft_fid'][$k];
                 $datapluginall=$this->db->db_set_recordset($sql);
                 $arraydatadelete=array();
                 if(count($datapluginall))
                 {
                 foreach($datapluginall as $valuepluginall)
                 {
                 
              
                 if(in_array($valuepluginall['plugid'],$this->post['ft_plugin'][$k]))
                 {
                 
                 
                 
                 }else
                 {
                 $arraydatadelete[]=$valuepluginall['fplugin'];
                 
                 }
                 
                 
                 }
                 
                 }
                 
                 

                 
                 
                 
                 foreach($this->post['ft_plugin'][$k] as $valueplugin)
                    {
                    
                        
                        if($valueplugin)
                        {
                        
                        $sql='select * from tb_feature_plugin where fid='.$this->post['ft_fid'][$k].' and plugid='.$valueplugin;
                        $dataplugincheck=$this->db->db_set_1recordrow($sql);
                        if($dataplugincheck['fplugin'])
                        {
                        
                        
                        
                        
                        }else
                        {
                        
                        
                        
                        $sql='select * from tb_plugins where plugid='.$valueplugin;
                        $dataplugin=$this->db->db_set_1recordrow($sql);
                        
                        if($dataplugin['plugid'])
                        {
                        $arraydata3=array();
                        $arraydata3['fid']=$fid;
                        $arraydata3['plugid']=$dataplugin['plugid'];
                        $arraydata3['config']=$dataplugin['config'];
                        $this->db->db_set($arraydata3,'tb_feature_plugin');
                        }
                        
                        }
                   
                       
                        }
                    
                    
                    }
                    
                    if(count($arraydatadelete))
                    {
                    foreach($arraydatadelete as $fvalueplugin)
                    {
                    if($fvalueplugin)
                    {
                    $sql="delete from tb_feature_plugin where fplugin=".$fvalueplugin;
                    $this->db->db_set_execute($sql);
                    }
                    
                    
                    
                    }
                    
                    
                    }
                 
                 
                 
                 }
                 
                 
                 
                 
                 
                 
                 
                 
                 }
                    
                    break;    
                    
                    
                    
              
            }
            
            
            
            if($fid)
            {
            
            $arraytag=array();
            $sql="delete from tb_tag_show where fid=".$fid;
            $this->db->db_set_execute($sql);
            if(count($this->post['ft_sytag'][$k]))
            {
            foreach($this->post['ft_sytag'][$k] as $valuetag)
            {
            $valuetag= trim($valuetag);
            if($valuetag)
            {
            
            $sql="select tagid from tb_tag where tb_tag.name='".$valuetag."'";
            $datatag=$this->db->db_set_1recordrow($sql);
            if($datatag['tagid'])
            {
            $sql='select stagid from tb_tag_show where tb_tag_show.tagid='.$datatag['tagid'].' and tb_tag_show.fid='.$fid;
            $datatagre=$this->db->db_set_1recordrow($sql);
            if(!$datatagre['stagid'])
            {
            $arraytagre=array();
            $arraytagre['fid']=$fid;
            $arraytagre['tagid']=$datatag['tagid'];
            $this->db->db_set($arraytagre,'tb_tag_show');
            
            }
            
            }else
            {
            
            $arraytag2=array();
            $arraytag2['name']=$valuetag;
            $arraytag2['all']=0;
            $arraytag2['system']=1;
            $arraytag2['fid']=$fid;
            $arraytag2['createby']=$arrayuser['userid'];
            $arraytag2['createdate']=date("Y-m-d H:i:s");
            
            $this->db->db_set($arraytag2,'tb_tag');
            $tagid=$this->db->db_get_last_number();
            $arraytagre=array();
            $arraytagre['fid']=$fid;
            $arraytagre['tagid']=$tagid;
            $this->db->db_set($arraytagre,'tb_tag_show');
            
            
            }
            
            
            
            }
            
            
            
            }
            
            
            
            }
            
            
            
            
            
            }
            
            
            $k++;
            
            
            
            
            
            
            
            
            }
            
            
            $this->test();
            
            }
            
            
            
            }
          
          
          }
          
          function updatealldomain()
          {
          $sql='select * from tb_domain';
          $alldomain=$this->db->db_set_recordset($sql);
          if(count($alldomain))
          {
          foreach($alldomain as $valuedomain)
          {
          $domain=$valuedomain['domain'];
          
          file_get_contents($domain.'/ajax/test');
          
          
          
          
          
          }
          
          
          }
          
          
          }
          
          function saveuserscreen()
          {
             
             
             
             $arrayuser=$this->getuserbyoauth($this->userdata['oauth']);
            if($arrayuser['userid']&&$this->post&&($arrayuser['roleid']==3||$arrayuser['roleid']==4))
            {
            $k=0;
            if(count($this->post['productid']))
            {
            foreach($this->post['productid'] as $valueproduct)
            {
            
           //echo $valueproduct."\n";
           // echo $this->post['position'][$k]."\n";
            $arraydata=array();
            
            $arraydata['position']=$this->post['position'][$k];
            $this->db->db_set($arraydata,'tb_product',' productid='.$valueproduct);
           
            $k++;
            
            
            
            
            
            }
            }
            
            
            
            
            
            }
          
          
          
          
     
          
          
          
          
          
          }
          
          function checkuserdata()
          {
          if($this->post['datauser'])
          {
          
          $sql='select oauth,userid from tb_user where tb_user.username="'.$this->post['datauser'].'" or tb_user.email="'.$this->post['datauser'].'" or tb_user.emailfacebook="'.$this->post['datauser'].'" or tb_user.phone="'.$this->post['datauser'].'"';
          
          $userdata=$this->db->db_set_1recordrow($sql);
          
          if($userdata['userid'])
          {
          
         // $this->get['userid']=$userdata['userid'];
         // $this->getuserdata();
          
          $userdata2=$this->getuseralldata($userdata['oauth']);
          $this->arraydata['data']=$userdata2['userdata'];
          
          $this->arraydata['data']['credit']=$this->getcreditbyuserid($userdata['userid']);
          }else
          {
          $this->arraydata['error'][]=5;
          
          }
          
          
          
          
          
          }else
          {
          
          $this->arraydata['error'][]=5;
          }
          
          
          
          
          
          
          }
          
          
          
          function saveorderall()
          {
          $arrayuser=$this->getuserbyoauth($this->userdata['oauth']);
           
           if(count($this->post['suborder'])&&$this->post['status']&&($arrayuser['roleid']=='3'||$arrayuser['roleid']=='4'||$arrayuser['roleid']=='5'))
           {
           $arrayorder=array();
           $arrayorder['status']=$this->post['status'];
           $arrayorder['sumall']=$this->post['sumall'];
           $arrayorder['cash']=$this->post['cash'];
           $arrayorder['change']=$this->post['change'];
           $arrayorder['userid']=$this->post['userid'];
           $arrayorder['updateby']=$arrayuser['userid'];
           
           
           if($this->post['guestname']){ $arrayorder['guestname']=$this->post['guestname']; }
           
           $arrayorder['updatedate']=date('Y-m-d H:i:s');
           $new=0;
           if($this->post['order']||$this->post['orderid'])
           {
           if($this->post['order'])
           {
              $orderid=$this->post['order'];  
           }else
           {
              $orderid=$this->post['orderid'];
           }
           
           $this->db->db_set($arrayorder,'tb_product_order',' orderid='.$orderid);
           
           
           
           }else
           {
           $new=1;
           $arrayorder['createby']=$arrayuser['userid'];
           $arrayorder['createdate']=date('Y-m-d H:i:s');
           
           $this->db->db_set($arrayorder,'tb_product_order');
           $orderid=$this->db->db_get_last_number();
           
           
           }
           
           $sql='delete from tb_product_suborder where orderid='.$orderid;
           $this->db->db_delete($sql);
           
            if(count($this->post['suborder']))
           {
           foreach($this->post['suborder'] as $valuesuborder)
           {
           $arraysuborder=array(); 
           $arraysuborder['productid']=$valuesuborder['productid'];
           $arraysuborder['credit']=$valuesuborder['credit'];
           $arraysuborder['count']=$valuesuborder['count'];
           if($valuesuborder['productid'])
           {
           
           }else
           {
           
           $arraysuborder['title']=$valuesuborder['title'];
           }
           
           $arraysuborder['orderid']=$orderid;
           $arraysuborder['discount']=$valuesuborder['discount'];
           $arraysuborder['price']=$valuesuborder['price'];
           $arraysuborder['note']=$valuesuborder['note'];
           
           $this->db->db_set($arraysuborder,'tb_product_suborder');
           
           
           
           
           
           }
           
           }
           
           if($this->post['questionid']&&$new==1&&$orderid)
           {
           $arrayq['questionid']=$this->post['questionid'];
           $arrayq['orderid']=$orderid;
           $this->db->db_set($arrayq,'tb_product_question_relate');
           
           }
           
           
           }
          
          
          
          
          }
          
          function changeorderstatus()
          {
          $arrayuser=$this->getuserbyoauth($this->userdata['oauth']);
          if($this->post['orderid']&&$this->post['status']&&($arrayuser['roleid']=='3'||$arrayuser['roleid']=='4'||$arrayuser['roleid']=='5'))
          {
          $arrayorder['updateby']=$arrayuser['userid'];
          
          if($this->post['cash'])$arrayorder['cash']=$this->post['cash'];
          if($this->post['change'])$arrayorder['change']=$this->post['change'];
          
          
          $arrayorder['updatedate']=date('Y-m-d H:i:s');;
          if($this->post['guestname']){$arrayorder['guestname']=$this->post['guestname'];}
          $arrayorder['status']=$this->post['status'];
          $this->db->db_set($arrayorder,'tb_product_order',' orderid='.$this->post['orderid']);
          
          
          
          
          if(isset($this->post['questionid']))
          {
          $sql='select userid from tb_product_order orderid='.$this->post['orderid'];
          $orderproduct=$this->db->db_set_1recordrow($sql);
          
          $arrayq['gender']=$this->post['gender'];
          $arrayq['age']=$this->post['age'];
          
          if($this->post['questionid'])
          {
          
          
          $this->db->db_set($arrayq,'tb_product_question',' questionid='.$this->post['questionid']);
          
          
          }else
          {
          
          
          $arrayq['userid']=$orderproduct['userid'];
          $arrayq['createby']=$arrayuser['userid'];
          $arrayq['createdate']=date("Y-m-d H:i:s");
          $this->db->db_set($arrayq,'tb_product_question');
          
          $questionid=$this->db->db_get_last_number();
          
          $arrayq2['questionid']=$questionid;
          $arrayq2['orderid']=$this->post['orderid'];
          $this->db->db_set($arrayq2,'tb_product_question_relate');
          
          
          }
          
          }
          
          }
          
          }
          
          function checkquestiondata()
          {
          $arrayuser=$this->getuserbyoauth($this->userdata['oauth']);
          
          if(($arrayuser['roleid']=='3'||$arrayuser['roleid']=='4'||$arrayuser['roleid']=='5'))
          {
          if($this->post['userid'])
          {
          
          $sql='select * from tb_product_question where userid='.$this->post['userid'];
          $arraydata=$this->db->db_set_1recordrow($sql);
          
          
          if($arraydata['questionid'])
          {
          
          $this->arraydata['data']=intval($arraydata['questionid']);
          $this->arraydata['question']=$arraydata;
          
          }else
          {
          
          $this->arraydata['data']=0;
          
          
          }
          
          
          }else
          {
          
          $this->arraydata['data']=0;
          
          }
          
          
          }
          
          
          
          }
          
          function savequestiondata()
          {
          
          $arrayuser=$this->getuserbyoauth($this->userdata['oauth']);
          if(($arrayuser['roleid']=='3'||$arrayuser['roleid']=='4'||$arrayuser['roleid']=='5'))
          {
          $arraydata=array();
          $arraydata['gender']=$this->post['gender'];
          $arraydata['age']=$this->post['age'];
          $arraydata['userid']=$this->post['userid'];
          $arraydata['createby']=$arrayuser['userid'];
          $arraydata['createdate']=date("Y-m-d H:i:s");
          $this->db->db_set($arraydata,'tb_product_question');
          $this->arraydata['data']=$this->db->db_get_last_number();
          
          }else
          {
          
          
          
          
          }
          
          
          }
          
          function getorderall()
          {
          
          if($this->post['page']&&isset($this->post['status']))
          {
             $page=$this->post['page'];
             $page=(($page - 1) * 20);
             $limit="limit  $page,20";
          $sql='SELECT
*,DATE_FORMAT(tb_product_order.createdate
,\'%d/%m/%Y\') newdate,DATE_FORMAT(tb_product_order.createdate
,\'%l:%i %p\') newtime
FROM
tb_product_order
where tb_product_order.`status` = '.$this->post['status'].'
'.' order by tb_product_order.createdate desc '.$limit;

            $arraynewdata=array();
            $arraydata=$this->db->db_set_recordset($sql);
            if(count($arraydata))
            {$k=0;
            foreach($arraydata as $valuedata)
            {
            
            $sql='SELECT * FROM `tb_product_suborder` where orderid='.$valuedata['orderid'];
            $arraydata2=$this->db->db_set_recordset($sql);
            if(count($arraydata2))
            {
            $x=0;
            foreach($arraydata2 as $valuedata2)
            {
            if($valuedata2['productid'])
            {
            
            $sql='select title from tb_product where productid='.$valuedata2['productid'];
            
            $arrproduct=$this->db->db_set_1recordrow($sql);
            
            
        //    $arrproduct['img']=$this->getimagebyimgmid($arrproduct['imgmid']);
         //   $arrproduct['simg']=$this->getimagebyimgmid($arrproduct['simgmid']);
            
            $arraydata2[$x]['productlist']=$arrproduct;
            }else
            {
            $arraydata2[$x]['productlist']=array();
            
            }
            
            $x++;
            
            
            }
            
            }
            
            $arraydata[$k]['suborder']=$arraydata2;
            
            
            
            if($arraydata[$k]['userid']!='0')
            {
            $userdata=$this->getuserbyuserid($arraydata[$k]['userid']);
            
            $userdata2=$this->getuseralldata($userdata['oauth']);
            $arraydata[$k]['user']=$userdata2['userdata'];
            
            
            }else
            {
            $arraydata[$k]['user']=array();
            
            }
            
            
            $k++;
            
            }
            
            }
            
            $this->arraydata['data']=$arraydata;
            if($this->post['page']==1)
            {
            $sql='select count(*) as countproduct from tb_product_order where tb_product_order.`status` = '.$this->post['status'].'';
            $countdata=$this->db->db_set_1recordrow($sql);
            $this->arraydata['count']=intval($countdata['countproduct']);
            }else
            {
            $this->arraydata['count']=0;
            
            }

        
          
          
          }
          
          
          }
          
          function getproductdiscountdata()
          {
          
          $this->arraydata['data']=parent::getproductdiscountdata();
          
          }
          
           function gettagproductdata()
          {
          
          $this->arraydata['data']=parent::gettagproductdata();
          
          }
          
          
          function getproductpricedata()
          {
          
          $this->arraydata['data']=parent::getproductpricedata();
          
          }
          
          function getpoppularpricedata()
          {
          
          $this->arraydata['data']=parent::getpoppularpricedata();
          }
          
          
          
          function getallproductdatapos()
          {
          
          $arraydata['product']=parent::getproductpricedata();
          $arraydata['poppular']=parent::getpoppularpricedata();
          $arraydata['discount']=parent::getproductdiscountdata();
          
          $this->arraydata['data']=$arraydata;
          
          }
          
          function checkcodethepromotion()
          {
          if($this->post['code'])
          {
          
          
          
          
          
          $sql='SELECT
tb_product.title,
tb_plugins_discount.`code`,
tb_product.productid,
tb_product.simgmid,
tb_plugins_discount.startdate,
tb_plugins_discount.price,
tb_plugins_discount.enddate
FROM
tb_product
INNER JOIN tb_plugins_discount ON tb_product.productid = tb_plugins_discount.productid
where tb_plugins_discount.`code`="'.$this->post['code'].'" ';


        $arraydata=$this->db->db_set_1recordrow($sql);
        

        if($arraydata['productid'])
        {
        
        $start_ts = strtotime($arraydata['startdate']);
         $end_ts = strtotime($arraydata['enddate']);
         $user_ts = mktime();

  // Check that user date is between start & end
       if(($user_ts >= $start_ts) && ($user_ts <= $end_ts))
       {
        $arraydata['simg']= $this->getimagebyimgmid($arraydata['simgmid']);
        $this->arraydata['data']=$arraydata;
       
       }else
       {
       $this->arraydata['error'][]=39;
       
       }
        
       
        }else
        {
        $this->arraydata['error'][]=40;
        
        }
        
        
       
       
       

        }
          
          
          }
          
          
          
          function checkcodethepromotionuser()
          {
          if($this->post['code']&&$this->post['userid'])
          {
          
          
          
          
          
          $sql='SELECT
tb_product.title,
tb_plugins_discount.`code`,
tb_product.productid,
tb_product.simgmid,
tb_plugins_discount.startdate,
tb_plugins_discount.price,
tb_product.createby,
tb_plugins_discount.enddate
FROM
tb_product
INNER JOIN tb_plugins_discount ON tb_product.productid = tb_plugins_discount.productid

where tb_plugins_discount.`code`="'.$this->post['code'].'" and tb_product.createby='.$this->post['userid'];


        $arraydata=$this->db->db_set_1recordrow($sql);
        

        if($arraydata['productid'])
        {
        
        $start_ts = strtotime($arraydata['startdate']);
         $end_ts = strtotime($arraydata['enddate']);
         $user_ts = mktime();

  // Check that user date is between start & end
       if(($user_ts >= $start_ts) && ($user_ts <= $end_ts))
       {
        $arraydata['simg']= $this->getimagebyimgmid($arraydata['simgmid']);
        $this->arraydata['data']=$arraydata;
       
       }else
       {
       $this->arraydata['error'][]=39;
       
       }
        
       
        }else
        {
        $this->arraydata['error'][]=40;
        
        }
        
        
       
       
       

        }
          
          
          }
          
          
          function getorderlistdatabyuserids()
          {
          if($this->post['userid']&&$this->post['page'])
          {
          $this->arraydata['orderlist']=$this->getorderlistdatabyuserid($this->post['userid'],$this->post['page']);
          }
          
          }
          function getordermemberbyorderid()
          {
          $arrayuser=$this->getuserbyoauth($this->userdata['oauth']);
          if($this->get['orderid']&&$arrayuser['userid'])
          {
          $sql='SELECT
tb_product_order.orderid,
tb_product_order.point,
tb_product_order.`status`,
tb_product_order.sumall,
tb_product_order.cash,
tb_product_order.`change`,
tb_product_order.userid,
tb_product_order.payid,
tb_product_order.tspoid,
tb_product_order.tfid,
tb_product_order.cart,
tb_product_order.cartstatus,
tb_product_order.updateby,
tb_product_order.createby,
tb_product_order.updatedate,
IF (tb_product_setting.shopname is NULL,tb_user.displayname,tb_product_setting.shopname) as displayname,
IF (tb_product_setting.orderprefix is NULL,\'\',tb_product_setting.orderprefix) as orderprefix,
DATE_FORMAT(tb_product_order.createdate,\'%T %d/%m/%Y\') as newdate,
tb_user.username,
tb_user.simgmid,
tb_product_order.createdate
FROM
tb_product_order
INNER JOIN tb_user ON tb_product_order.createby=tb_user.userid
LEFT JOIN tb_product_setting ON tb_product_order.createby=tb_product_setting.createby
where tb_product_order.orderid='.$this->get['orderid'].' and tb_product_order.userid='.$arrayuser['userid'];
            $arrrayorder=$this->db->db_set_1recordrow($sql);
            $arrrayorder['simg']=$this->getimagebyimgmid($arrrayorder['simgmid']);
            if($arrrayorder['orderid'])
            {
            
            $sql='select * from tb_product_transport where tspoid='.$arrrayorder['tspoid'];
            $arrrayorder['transport']=$this->db->db_set_1recordrow($sql);
            
            
            $sql='select displayname,emailcontact,phone,shipaddress,shipcountryid,shipproid,shipdisid,shiptumid,shipstate,shipcode from tb_user where userid='.$arrrayorder['userid'];
            $arrrayorder['customer']=$this->db->db_set_1recordrow($sql);
            
            
            $arrrayorder['customer']['shipcountryname']=$this->getcountrynamebycoutryid($arrrayorder['customer']['shipcountryid']);
            $arrrayorder['customer']['shipproname']=$this->getprovincebyproid($arrrayorder['customer']['shipproid']);
            $arrrayorder['customer']['shipdistrictname']=$this->getdistrictbydisid($arrrayorder['customer']['shipdisid']);
            $arrrayorder['customer']['shiptumname']=$this->gettumbonbytumid($arrrayorder['customer']['shiptumid']);
            if($arrrayorder['customer']['shipcountryid']=='210')
            {
            
$arrrayorder['customer']['shipaddressall']=$arrrayorder['customer']['shipaddress'].' '.$arrrayorder['customer']['shipdistrictname'].' '.$arrrayorder['customer']['shiptumname'].' '.$arrrayorder['customer']['shipcode'];
            }else
            {
            
            $arrrayorder['customer']['shipaddressall']=$arrrayorder['customer']['shipaddress'].' '.$arrrayorder['customer']['shipcountryname'].$arrrayorder['customer']['shipstate'];
            
            }
            
            
            $sql='SELECT
tb_product_suborder.suborderid,
tb_product_suborder.productid,
tb_product_suborder.credit,
tb_product_suborder.point,
tb_product_suborder.count,
tb_product_suborder.`delete`,
tb_product_suborder.orderid,
tb_product_suborder.title,
tb_product_suborder.note,
tb_product_suborder.discount,
tb_product_suborder.price,
tb_product.title,
tb_product.simgmid
FROM
tb_product_suborder
INNER JOIN tb_product ON tb_product_suborder.productid = tb_product.productid
where tb_product_suborder.orderid='.$arrrayorder['orderid'];
            
            $arrrayorder['suborder']=$this->db->db_set_recordset($sql);
            $k=0;
            $note='';
            if(count($arrrayorder['suborder']))
            {
            foreach($arrrayorder['suborder'] as $valuesuborder)
            {
            $note=$valuesuborder['note'];
            $arrrayorder['suborder'][$k]['simg']=$this->getimagebyimgmid($valuesuborder['simgmid']);
            $arrrayorder['suborder'][$k]['sum']=intval($valuesuborder['price'])*intval($valuesuborder['count']);
            $k++;
            
            }
            
            }
            $arrrayorder['note']=$note;
            
            
            $sql='SELECT
tb_product_transfer_bank.bankname,
tb_product_transfer.accnumber,
tb_product_transfer.accname,
tb_product_transfer.branch,
tb_product_transfer_type.typename,
tb_product_userpay.upayid,
tb_product_userpay.tfid,
tb_product_userpay.orderid,
tb_product_userpay.shopid,
DATE_FORMAT(tb_product_userpay.createdate,\'%T %d/%m/%Y\') as newcreatedate,
DATE_FORMAT(tb_product_userpay.datepay,\'%d/%m/%Y\') as newdatepay,
DATE_FORMAT(tb_product_userpay.datepay,\'%T\') as newtimedatepay,
tb_product_userpay.datepay,
tb_product_userpay.amount,
tb_product_userpay.detail,
tb_product_userpay.imgmid,
tb_product_userpay.simgmid,
tb_product_userpay.createby,
tb_product_userpay.createdate
FROM
tb_product_userpay
INNER JOIN tb_product_transfer ON tb_product_userpay.tfid = tb_product_transfer.tfid
INNER JOIN tb_product_transfer_bank ON tb_product_transfer.bankid = tb_product_transfer_bank.bankid
INNER JOIN tb_product_transfer_type ON tb_product_transfer.actypeid = tb_product_transfer_type.actypeid
where tb_product_userpay.orderid='.$arrrayorder['orderid'];

            $arrrayorder['userpay']=$this->db->db_set_recordset($sql);
            
            
            $k=0;
            
            if(count($arrrayorder['userpay']))
            {
            foreach($arrrayorder['userpay'] as $valuesuborder)
            {
            
            $arrrayorder['userpay'][$k]['simg']=$this->getimagebyimgmid($valuesuborder['simgmid']);
            $arrrayorder['userpay'][$k]['img']=$this->getimagebyimgmid($valuesuborder['imgmid']);
            $k++;
            
            }
            
            }
            
            $this->arraydata['data']=$arrrayorder;
            
            
            }
            else
            {
            $htis->arraydata['error'][]=26;
            }
          
          
          }
          
          
          }
          
          function getrefnodata()
          {
          $arrayuser=$this->getuserbyoauth($this->userdata['oauth']);
          if($this->get['orderid']&&$arrayuser['userid'])
          {
          
          $sql='SELECT
tb_product_shipping.pshipid,
tb_product_shipping.`code`,
tb_product_shipping.orderid,
tb_product_shipping.note,
tb_product_shipping.createby,
tb_product_shipping.createdate
FROM
tb_product_shipping where tb_product_shipping.orderid='.$this->get['orderid'].' order by tb_product_shipping.createdate desc';

            $this->arraydata['data']=$this->db->db_set_1recordrow($sql);
          
          
          }
          
          }
          

          function getordershopbyorderid()
          {
          $arrayuser=$this->getuserbyoauth($this->userdata['oauth']);
          if($this->get['orderid']&&$arrayuser['userid'])
          {
          $sql='SELECT
tb_product_order.orderid,
tb_product_order.point,
tb_product_order.`status`,
tb_product_order.sumall,
tb_product_order.cash,
tb_product_order.`change`,
tb_product_order.userid,
tb_product_order.payid,
tb_product_order.tspoid,
tb_product_order.tfid,
tb_product_order.cart,
tb_product_order.cartstatus,
tb_product_order.updateby,
tb_product_order.createby,
tb_product_order.updatedate,
tb_user.displayname,
IF (tb_product_setting.orderprefix is NULL,\'\',tb_product_setting.orderprefix) as orderprefix,
DATE_FORMAT(tb_product_order.createdate,\'%T %d/%m/%Y\') as newdate,
tb_user.username,
tb_user.simgmid,
tb_product_order.createdate
FROM
tb_product_order
INNER JOIN tb_user ON tb_product_order.userid=tb_user.userid
LEFT JOIN tb_product_setting ON tb_product_order.createby=tb_product_setting.createby
where tb_product_order.orderid='.$this->get['orderid'].' and tb_product_order.createby='.$arrayuser['userid'];
            $arrrayorder=$this->db->db_set_1recordrow($sql);
            $arrrayorder['simg']=$this->getimagebyimgmid($arrrayorder['simgmid']);
            if($arrrayorder['orderid'])
            {
            
            $sql='select * from tb_product_transport where tspoid='.$arrrayorder['tspoid'];
            $arrrayorder['transport']=$this->db->db_set_1recordrow($sql);
            
            
            $sql='select displayname,emailcontact,phone,shipaddress,shipcountryid,shipproid,shipdisid,shiptumid,shipstate,shipcode from tb_user where userid='.$arrrayorder['userid'];
            $arrrayorder['customer']=$this->db->db_set_1recordrow($sql);
            
            
            $arrrayorder['customer']['shipcountryname']=$this->getcountrynamebycoutryid($arrrayorder['customer']['shipcountryid']);
            $arrrayorder['customer']['shipproname']=$this->getprovincebyproid($arrrayorder['customer']['shipproid']);
            $arrrayorder['customer']['shipdistrictname']=$this->getdistrictbydisid($arrrayorder['customer']['shipdisid']);
            $arrrayorder['customer']['shiptumname']=$this->gettumbonbytumid($arrrayorder['customer']['shiptumid']);
            if($arrrayorder['customer']['shipcountryid']=='210')
            {
            
$arrrayorder['customer']['shipaddressall']=$arrrayorder['customer']['shipaddress'].' '.$arrrayorder['customer']['shipdistrictname'].' '.$arrrayorder['customer']['shiptumname'].' '.$arrrayorder['customer']['shipcode'];
            }else
            {
            
            $arrrayorder['customer']['shipaddressall']=$arrrayorder['customer']['shipaddress'].' '.$arrrayorder['customer']['shipcountryname'].$arrrayorder['customer']['shipstate'];
            
            }
            
            
            $sql='SELECT
tb_product_suborder.suborderid,
tb_product_suborder.productid,
tb_product_suborder.credit,
tb_product_suborder.point,
tb_product_suborder.count,
tb_product_suborder.`delete`,
tb_product_suborder.orderid,
tb_product_suborder.title,
tb_product_suborder.note,
tb_product_suborder.discount,
tb_product_suborder.price,
tb_product.title,
tb_product.simgmid
FROM
tb_product_suborder
INNER JOIN tb_product ON tb_product_suborder.productid = tb_product.productid
where tb_product_suborder.orderid='.$arrrayorder['orderid'];
            
            $arrrayorder['suborder']=$this->db->db_set_recordset($sql);
            $k=0;
            $note='';
            if(count($arrrayorder['suborder']))
            {
            foreach($arrrayorder['suborder'] as $valuesuborder)
            {
            $note=$valuesuborder['note'];
            $arrrayorder['suborder'][$k]['simg']=$this->getimagebyimgmid($valuesuborder['simgmid']);
            $arrrayorder['suborder'][$k]['sum']=intval($valuesuborder['price'])*intval($valuesuborder['count']);
            $k++;
            
            }
            
            }
            $arrrayorder['note']=$note;
            
            
            $sql='SELECT
tb_product_transfer_bank.bankname,
tb_product_transfer.accnumber,
tb_product_transfer.accname,
tb_product_transfer.branch,
tb_product_transfer_type.typename,
tb_product_userpay.upayid,
tb_product_userpay.tfid,
tb_product_userpay.orderid,
tb_product_userpay.shopid,
DATE_FORMAT(tb_product_userpay.createdate,\'%T %d/%m/%Y\') as newcreatedate,
DATE_FORMAT(tb_product_userpay.datepay,\'%d/%m/%Y\') as newdatepay,
DATE_FORMAT(tb_product_userpay.datepay,\'%T\') as newtimedatepay,
tb_product_userpay.datepay,
tb_product_userpay.amount,
tb_product_userpay.detail,
tb_product_userpay.imgmid,
tb_product_userpay.simgmid,
tb_product_userpay.createby,
tb_product_userpay.createdate
FROM
tb_product_userpay
INNER JOIN tb_product_transfer ON tb_product_userpay.tfid = tb_product_transfer.tfid
INNER JOIN tb_product_transfer_bank ON tb_product_transfer.bankid = tb_product_transfer_bank.bankid
INNER JOIN tb_product_transfer_type ON tb_product_transfer.actypeid = tb_product_transfer_type.actypeid
where tb_product_userpay.orderid='.$arrrayorder['orderid'];

            $arrrayorder['userpay']=$this->db->db_set_recordset($sql);
            
            
            $sql='SELECT
tb_product_shipping.pshipid,
tb_product_shipping.`code`,
tb_product_shipping.orderid,
tb_product_shipping.note,
tb_product_shipping.createby,
tb_product_shipping.createdate
FROM
tb_product_shipping where tb_product_shipping.orderid='.$arrrayorder['orderid'].' order by tb_product_shipping.createdate desc';

            $arrrayorder['shipping']=$this->db->db_set_1recordrow($sql);

    
            
            
            $k=0;
            
            if(count($arrrayorder['userpay']))
            {
            foreach($arrrayorder['userpay'] as $valuesuborder)
            {
            
            $arrrayorder['userpay'][$k]['simg']=$this->getimagebyimgmid($valuesuborder['simgmid']);
            $arrrayorder['userpay'][$k]['img']=$this->getimagebyimgmid($valuesuborder['imgmid']);
            $k++;
            
            }
            
            }
            
            $this->arraydata['data']=$arrrayorder;
            
            
            }
            else
            {
            $htis->arraydata['error'][]=26;
            }
          
          
          }
          
          
          }
          
          function getmemberorder()
          {
          
           if($this->get['page'])
           {
           $page=$this->get['page'];
             $page=(($page - 1) * 8);
             $limit="limit  $page,8";
             
           $str='where shop=0';
          if($this->get['status'])
          {
          $str='where shop='.$this->get['status'].'';
          
          }
          
          
          
          $sql='SELECT * FROM (
SELECT
tb_user.userid,
tb_product_order.orderid
FROM
tb_user
LEFT JOIN tb_product_order ON tb_user.userid = tb_product_order.userid
'.$str.'
ORDER BY orderid desc ) tb_user 
GROUP BY userid ORDER BY orderid desc 
'.$limit;

           $arraydataproduct =$this->db->db_set_recordset($sql);
           $arraynewdata=array();
           $k=0;
           if(count($arraydataproduct))
           {
           foreach($arraydataproduct as $valueuser)
           {
           $arraydata=$this->getorderlistbyuserid($valueuser['userid']);
           

            $userdata=$this->getuserbyuserid($valueuser['userid']);
            
            $userdata2=$this->getuseralldata($userdata['oauth']);
            $arraydata['user']=$userdata2['userdata'];
            $arraydata['user']['credit']=$this->getcreditbyuserid($userdata2['userdata']['userid']);
            
              $sql='select * from tb_product_question where userid='.$userdata2['userdata']['userid'];
          $arraydataq=$this->db->db_set_1recordrow($sql);
          
          
          if($arraydataq['questionid'])
          {
          

          $arraydata['user']['question']=$arraydataq;
          
          }else
          {
          
          $arraydata['user']['question']=array();
          
          }
            
            
          
           
           $arraynewdata[$k]=$arraydata;
           $k++;
           }
           
           }
           
          
          
          
          
          
          $this->arraydata['data']=$arraynewdata;
          $sql='SELECT count(tb_user.userid) as countuser FROM tb_user where shop=1';
          $countuser=$this->db->db_set_1recordrow($sql);
          $this->arraydata['countallshop']=intval($countuser['countuser']);
          
          
          
          $sql='SELECT count(tb_user.userid) as countuser FROM tb_user where shop=0';
          $countuser=$this->db->db_set_1recordrow($sql);
          $this->arraydata['countallnoshop']=intval($countuser['countuser']);
          
           }
          
          
          }
          
          
          function savenewregister()
          {
          $arrayuser=$this->getuserbyoauth($this->userdata['oauth']);
          $arraylog['test']='user->'.json_encode($arrayuser).' and post->'.json_encode($this->post);
          $this->db->db_set($arraylog,'tb_log');
          if(($arrayuser['roleid']=='3'||$arrayuser['roleid']=='4'||$arrayuser['roleid']=='5'))
          {
            $username=$this->post['username'];
           $check1=$this->checkusername($username);
           
           $email=$this->post['email'];
           $check2=$this->checkemail($email);
          
           if($check1==1&&$check2==1)
                {
                $password=123456;
                $password=md5(strtolower($username) . $password);
                
                $arraydata['username']=$username;
                $arraydata['displayname']=$username;
                $arraydata['oauth']=md5($password.time());
                $arraydata['status']=1;
                $arraydata['password']=$password;
                $arraydata['lat']=$this->post['lat'];
                $arraydata['lng']=$this->post['lng'];
                $arraydata['address']=$this->post['address'];
                $arraydata['tumid']=$this->post['tumid'];
                $arraydata['disid']=$this->post['disid'];
                $arraydata['proid']=$this->post['proid'];
                $arraydata['birthdate']=$this->post['birthdate'];
                $arraydata['email']=$this->post['email'];
                $arraydata['phone']=$this->post['phone'];
                $arraydata['username']=$this->post['username'];
                
                 if($this->post['photomain'])
                       {
                      $arraydata['imgmid']= $this->savephotobase64($this->post['photomain']);
                      $arraydata['simgmid']= $arraydata['imgmid'];
                      
                       }else
                       {
                       $arraydata['imgmid']=$this->post['imgmid'];
                $arraydata['simgmid']=$this->post['simgmid'];
                       }
                
                
                
                $arraydata['shop']=1;
                
                
                $this->db->db_set($arraydata,'tb_user');
                $userid=$this->db->db_get_last_number();
                $this->arraydata['userid']=$userid;
                
            $userdata=$this->getuserbyuserid($userid);
            
            $userdata2=$this->getuseralldata($userdata['oauth']);
            $this->arraydata['data']=$userdata2['userdata'];
            $this->arraydata['data']['credit']=$this->getcreditbyuserid($userid);
            
                


                }
                else
           {
           if($check1!=1)$this->arraydata['error'][]=$check1;
           if($check2!=1)$this->arraydata['error'][]=$check2;

           
           }
          
          }
          
          
          }
          
          function loadnewgrouptag()
          {
          if($this->post['fid'])
          {
          
          $sql='select * from tb_group_tag where fid='.$this->post['fid'].' order by tb_group_tag.order asc';
          $arraydata=$this->db->db_set_recordset($sql);
          $k=0;
          if(count($arraydata))
          {
          foreach($arraydata as $valuedata)
          {
          
          $arraydata[$k]['img']=$this->getimagebyimgmid($arraydata[$k]['imgmid']);;
          $arraydata[$k]['simg']=$this->getimagebyimgmid($arraydata[$k]['simgmid']);;
          
          $k++;
          
          }
          
          }
          
          $this->arraydata['data']=$arraydata;
          
          
          $sql='select * from tb_feature where fid='.$this->post['fid'];
          $arraydata2=$this->db->db_set_1recordrow($sql);
          
          
          $dataarray=json_decode($arraydata2['config']);
          $arraydata2=object_to_array($dataarray);
          
          if($arraydata2['istag'])
          {
          
          $this->arraydata['istag']=1;
          
          }else
          {
          $this->arraydata['istag']=0;
          }
          
          
          
          
          
          }
          
          
          }
          
           function userchecktag()
            {
            $arrayuser=$this->getuserbyoauth($this->userdata['oauth']);
            if($arrayuser['userid'])
              {
              $sql='select * from tb_user_tag where createby='.$arrayuser['userid'];
              $this->arraydata['data']=$this->db->db_set_recordset($sql);
              if($this->post['fid'])
              {
              $sql='select * from tb_group_tag where fid='.$this->post['fid'];
              $arraytag=$this->db->db_set_recordset($sql);
              }else
              {
              $arraytag=array();
              }
              
              $this->arraydata['data2']=$arraytag;
              
              }
            
            
            }
           function saveusertag()
           {
           $arrayuser=$this->getuserbyoauth($this->userdata['oauth']);
           if($this->post['tag']&&$arrayuser['userid'])
           {
           $arraytag['tag']=$this->post['tag'];
           $arraytag['createby']=$arrayuser['userid'];
           $arraytag['createdate']=date("Y-m-d H:i:s");
           $this->db->db_set($arraytag,'tb_user_tag');
           }
           
           }
           
           function deleteusertag()
           {
           $arrayuser=$this->getuserbyoauth($this->userdata['oauth']);
           if($this->post['utagid']&&$arrayuser['userid'])
           {
           $sql='delete from tb_user_tag where utagid='.$this->post['utagid'].' and createby='.$arrayuser['userid'];
           $this->db->db_delete($sql);
           }
           
           }
          
          function savenewgrouptag()
          {
          if($this->post['fid']&&count($this->post['data']))
          {
          $sql='delete from tb_group_tag where fid='.$this->post['fid'];
          $this->db->db_delete($sql);
          
          
          
          $sql='select * from tb_feature where fid='.$this->post['fid'];
          $arraydata2=$this->db->db_set_1recordrow($sql);
          
          
          $dataarray=json_decode($arraydata2['config']);
          $arraydata2=object_to_array($dataarray);
          
          $arraydata2['istag']=intval($this->post['active']);
          
          $arrayset['config']=json_encode($arraydata2);
          
          
          $this->db->db_set($arrayset,'tb_feature','fid='.$this->post['fid']);
          
          
          foreach($this->post['data'] as $valuedata)
          {
          $arraynewdata=array();
          $arraynewdata['order']=$valuedata['order'];
          $arraynewdata['imgmid']=$valuedata['imgmid'];
          $arraynewdata['simgmid']=$valuedata['simgmid'];
          $arraynewdata['fid']=$this->post['fid'];
          $arraynewdata['tag']=$valuedata['tag'];
          $arraynewdata['createdate']=date("Y-m-d H:i:s");
          
          $this->db->db_set($arraynewdata,'tb_group_tag');
          
          
          
          }
          
          
          $this->test();
          
          
          }
          
          
          
          }
          
          function syncfacebookdata()
          {
           
          $arrayuser=$this->getuserbyoauth($this->userdata['oauth'],',syncfacebook,syncuser,email,emailfacebook,facebookid');
          
          if($arrayuser['facebookid'])
          {
          if($arrayuser['syncfacebook']=='1')
          {
          $this->arraydata['error'][]=27; 
          
          }else
          {
          if(($this->post['username']||$this->post['email'])&&$this->post['password'])
          {
          
            $email=$this->post['email'];
           $username=$this->post['username'];
           $password=$this->post['password'];
           $datauser=$this->loginuser($username,$email,$password,1);
           
           if($datauser['userid']&&$datauser['status']==1)
           {
           
           $this->tranferuserto($datauser['userid'],$arrayuser['userid']);
           
           $this->tranferdatato($datauser['userid'],$arrayuser['userid']);

           
           
           }else
          {
          $this->arraydata['error'][]=3;
          
          }
          
          
          }
          else if($this->post['susername']&&$this->post['semail']&&$this->post['spassword'])
          {
          
           $username=$this->post['susername'];
           $check1=$this->checkusername($username);
           
           $email=$this->post['semail'];
           $check2=$this->checkemail($email);
          
           if($check1==1&&$check2==1)
           {
           $userArray=array();
           $userArray['username']=$username;
           $userArray['email']=$email;
           $md5password=md5($this->post['spassword'].'-123456');
           $userArray['password']=$md5password;
           $userArray['oauth']=$this->userdata['oauth'];
           $userArray['syncfacebook']=1;
           $userArray['syncuser']=1;
            $time=0;
           if($_COOKIE['timelimit'])
           {
           $time=intval($_COOKIE['timelimit']);
           }
            $domain='';
            if(NameDmconnex=="Canonlife"){
            $url='http://'.$_SERVER['HTTP_HOST'];
            $domain='.'.get_domain($url);
            }
           setcookie("username",$username, $time, "/",$domain);
           
           
           $this->db->db_set($userArray,'tb_user','userid='.$arrayuser['userid']);
           
           }else
           {
            if($check1!=1)$this->arraydata['error'][]=$check1;
            if($check2!=1)$this->arraydata['error'][]=$check2;
           
           }
          
          }
          
          
          
          
          }
          
          
          
          }
          
          
          
          }
          
          function synceuserdata()
          {
          
          echo md5("chaibird-123456");
          
          }
          
          function checkfacebookconnect()
          {
         // $sql='select * from tb_bird where bird="1" and  bired2='."'test'";
//          $this->db->db_set_1recordrow($sql);
         // exit;
         if($this->userdata['oauth'])
         {
          $arrayuser=$this->getuserbyoauth($this->userdata['oauth'],',syncfacebook,syncuser,email,emailfacebook,facebookid,readsync');
          
          if($arrayuser['facebookid'])
          {
          
          if($arrayuser['syncfacebook']=='1')
          {
          
          $this->arraydata['data']=false; 
          
          
          }else
          {
          if($arrayuser['readsync']=='1')
          {
          $this->arraydata['data']=false; 
          }else{
          
          $arraycheckuser['readsync']=1;
          $this->db->db_set($arraycheckuser,'tb_user',' userid='.$arrayuser['userid']);
          
          if($arrayuser['emailfacebook'])
          {
          
          $sql='select userid from tb_user where tb_user.email="'.$arrayuser['emailfacebook'].'" and tb_user.syncfacebook=0 and tb_user.userid !='.$arrayuser['userid'];
          
          $arraycheck=$this->db->db_set_1recordrow($sql);
          
          if($arraycheck['userid'])
          {
          
          $this->tranferuserto($arraycheck['userid'],$arrayuser['userid']);
        
          
          
          $this->tranferdatato($arraycheck['userid'],$arrayuser['userid']);
          $this->arraydata['data']=false; 
          
          }else
          {
          
          
          $this->arraydata['data']=true; 
          
          }
          
          
          
          }
          else
          {
          $this->arraydata['data']=true; 
          
          }
          }
          
          
          }
          
          
          
          
          }else
          {
          
         $this->arraydata['data']=false; 
          
          }
         }else
         {
         
           $this->arraydata['data']=false; 
         }
          
          
          
          
          
          }
          
          function testsyncf()
          {
          
          $this->tranferuserto(7,1);
          
          }
          
          function testpostcurldata()
          {
      //    $url='http://canonlife.com/ajax/saveproductmobiledata';
      //    $_POST['test']=1;
      //    FetchContent($url,'','C:\Documents and Settings\Administrator\Local Settings\Temporary Internet Files\cookies.txt',$url,$_POST,1);
          
          
          }
          
          function checkuserfacebookconnect()
          {
              
             $arrayuser=$this->getuserbyoauth($this->userdata['oauth'],',syncfacebook,syncuser,email,emailfacebook,facebookid');
             
             if($arrayuser['userid']&&$arrayuser['syncfacebook']=='0')
             {
             
             
             
             
          
             require pluginpath.'/facebook/facebook.php';

            
            $facebook = new Facebook(array(
            'appId'  =>facebookappid,
            'secret' =>facebooksecret,
            ));
            
            
            $user = $facebook->getUser();
            
            
            if ($user) {
            try {
            // Proceed knowing you have a logged in user who's authenticated.
            $user_profile = $facebook->api('/me');
            } catch (FacebookApiException $e) {
            error_log($e);
            $user = null;
            }
            }
            
            
            $this->post['facebookid']=$user_profile['id'];
            $this->post['firstname']=$user_profile['first_name'];
            $this->post['lastname']=$user_profile['last_name'];
            $this->post['email']=$user_profile['email'];

            
            
            
            $datauser=$this->loginfacebook($this->post['facebookid'],$this->post['email'],$this->post['firstname'],$this->post['lastname'],$this->post['gender'],$arrayuser['userid']);
            
            if($datauser['hasuser']&&$datauser['userto'])
            {
            $this->tranferdatato($datauser['userto'],$arrayuser['userid']);
            
            
            }
          
              if($this->get['linkto'])
             {
             $linkto=baseinfo.$this->get['linkto'];
             alert('',$linkto); 
             }
             
            
            }
          
          }
          
          function getalluserdataorder()
          {
          if($this->get['page'])
          {
          $page=(($page - 1) * 8);
          $limit="limit  $page,8";
          $sql='select oauth,userid  from tb_user  '.$limit;
          
          $arrayuser=$this->db->db_set_recordset($sql);
          $k=0;
          if(count($arrayuser))
          {
          foreach($arrayuser as $valueuser)
          {
          
          $userdata2=$this->getuseralldata($valueuser['oauth']);
          $arrayuser[$k]=$userdata2['userdata'];
          $arrayuser[$k]['credit']=$this->getcreditbyuserid($valueuser['userid']);
        //  $arrayuser[$k]['credit']=$this->getcreditbyuserid($valueuser['userid']);
          $k++;
          }
          
          
          }
          
          
          
          }
          
          }
          
          function getallexitdataimg()
          {
          header("Content-Type: application/vnd.ms-excel");
          header('Content-Disposition: attachment; filename="'.time().'-'.rand(0,100).'.xls"');
          $sql='select other,path from tb_img where other !="" and other !="false" and other like "%IFD0%" and other like "%Make%" ';
          $dataimg=$this->db->db_set_recordset($sql);
          $arraynewdata=array();
               echo '<html xmlns:o="urn:schemas-microsoft-com:office:office"

xmlns:x="urn:schemas-microsoft-com:office:excel"

xmlns="http://www.w3.org/TR/REC-html40">


<HTML>

<HEAD>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

</HEAD><BODY>';
   echo '<table x:str BORDER="1"><tbody><tr><th>ลำดับ</th>
                                        <th>Path</th><th>Exifdata</th></tr>';
          if(count($dataimg))
          {$k=0;
          foreach($dataimg as $valueimg)
          {
          $arrayother=json_decode($valueimg['other']);
          //$arraynewdata[$k]['path']=$valueimg['path'];
         // $arraynewdata[$k]['mode']=$arrayother->IFD0;
          
          echo '<tr>';
          echo '<td>';
          echo $k+1;
          echo '</td>';
          echo '<td>';
          echo  '<a href="'.baseinfo.'/'.$valueimg['path'].'">'.baseinfo.'/'.$valueimg['path'].'</a>';
          echo '</td>';
          echo '<td>';
          
          
          echo "<pre>";
          print_r($arrayother->IFD0);
          echo "</pre>;";
          
          echo '</td>';
          
          echo '</tr>';
          $k++;

          

          
          
          }
          }
          
   echo '</table>';
   
          
          
          
          }
          
          
          function checkserialnumberdata()
            {
            if($this->post['serial'])
            {
            $model=$this->gotocheck($this->post['serial'],1);
            }
            
            $this->arraydata['data']=$model;
            
            }
            
            
          function checkserialnumberdata3()
            {
            if($this->get['serial'])
            {
            $model=$this->gotocheckcanonserial($this->get['serial']);
            }
            
            $this->arraydata['data']=$model;
            
            }
            
          function checkserialnumberdata2()
            {
            $sql=" select * from tb_serial where serial<>'' and (description='NULL' or description='' ) and serialid>313 ";
            
            $arrayserial=$this->db->db_set_recordset($sql);
            if(count($arrayserial))
            {
            foreach($arrayserial as $valueserial)
            {
            if($valueserial['serial'])
            {
            $modeldata=$this->gotocheckcanonserial($valueserial['serial']);
            sleep(2);
            $arraydata=array();
            $arraydata['model']=$modeldata['ModelName'];
            $arraydata['description']=$modeldata['Description'];
            $arraydata['productcategory']=$modeldata['Product_Category'];
            $arraydata['productdivision']=$modeldata['Product_Division'];
            $arraydata['stockcode']=$modeldata['StockCode'];
            $arraydata['warrantynumber']=$modeldata['WarrantyNumber'];
            $this->db->db_set($arraydata,'tb_serial',' serialid='.$valueserial['serialid']);
            }
            
            
            }
            
            
            
            }
            
            
            
            $this->arraydata['data']=$model;
            
            }  
            
            
          function getserialbyuserid()
          {
            
             $arrayuser=$this->getuserbyoauth($this->userdata['oauth']);
             
             if($arrayuser['userid'])
             {
             $sql='SELECT
tb_serial.serial,
tb_serial.model,
DATE_FORMAT(tb_serial.createdate
,\'%d/%m/%Y\') newdate,
tb_serial_model.modelname,
tb_serial_model.modelid
FROM
tb_serial
INNER JOIN tb_serial_model ON tb_serial.modelid = tb_serial_model.modelid
where tb_serial.createby='.$arrayuser['userid'].'
ORDER BY tb_serial_model.modelid asc
';
             $arraydata=$this->db->db_set_recordset($sql);
             $arraynewdata=array();
             if(count($arraydata))
             {
             $k=0;
             $tempm='';
             foreach($arraydata as $valuedata)
             {

             
             $arraynewdata[$k]['modelname']=$valuedata['modelname'];
             $arraynewdata[$k]['modelid']=$valuedata['modelid'];
             $arraynewdata[$k]['data'][]=array('serial'=>$valuedata['serial'],'model'=>$valuedata['model'],'newdate'=>$valuedata['newdate']);
             
             if($tempm!=$valuedata['modelname'])
             {
             if($tempm!='')
             {
             
             $k++;
             }
             $tempm=$valuedata['modelname'];
             
             }
             
             
             
             
             
             
             }
             
             }
             
             $this->arraydata['data']=$arraynewdata;
             
             }
          
          
          
          }
          
          function saveserialdata()
          {
          
          $arrayuser=$this->getuserbyoauth($this->userdata['oauth']);
             
             if($arrayuser['userid']&&count($this->post['serialname'])&&count($this->post['modelname'])&&$this->post['modelid'])
             {
                 $k=0;
                foreach($this->post['serialname'] as $valueserial)
                {
                
                         $status= $this->checkserial($valueserial);
                          if(is_bool($status))
                          {
                          
                          $arraydata['serial']=$valueserial;
                          $arraydata['model']=$this->post['modelname'][$k];
                          $arraydata['modelid']=$this->post['modelid'];
                          $arraydata['createby']=$arrayuser['userid'];
                          $arraydata['createdate']=date("Y-m-d H:i:s");
                          
                          $this->db->db_set($arraydata,'tb_serial');
                          
                          if(NameDmconnex=="Canonlife"){ 
                          
                          
                           $arraydata2=array();
                           $arraydata2['roleid']=2;
                           $this->db->db_set($arraydata2,'tb_user',' userid='.$userid);
                          
                          }
                          
                          
                          
                          }else
                          {
                          
                          $this->arraydata['error'][]=$status;
                          
                          }
                          $k++;
                
                }
             
             }
          
          
          
          }
            
          function savebanneruser()
          {
            if($this->userdata['oauth'])
            {
            $arrayuser=$this->getuserbyoauth($this->userdata['oauth']);
            if($arrayuser['userid'])
            {
            if($this->post['pname']&&$this->post['imgmid']&&$this->post['simgmid'])
            {
            $arraydata=array();
            $arraydata['pname']=$this->post['pname'];
            $arraydata['pemail']=$this->post['pemail'];
            $arraydata['imgmid']=$this->post['imgmid'];
            $arraydata['simgmid']=$this->post['simgmid'];
            $arraydata['updateby']=$arrayuser['userid'];
            $arraydata['updatedate']=date("Y-m-d H:i:s");
            if($this->post['pubid'])
            {
            
            $this->db->db_set($arraydata,'tb_banner_public',' pubid='.$this->post['pubid']);
            
            }else
            {
            $arraydata['createby']=$arrayuser['userid'];
            $arraydata['createdate']=date("Y-m-d H:i:s");
            
            $this->db->db_set($arraydata,'tb_banner_public');
            
            
            }
            
            }
            
            
            if(count($this->post['countdata']))
            {
            
            foreach($this->post['countdata'] as $valuedata)
            {
            $arraydata=array();
            $arraydata['imgmid']=$valuedata['imgmid'];
            $arraydata['simgmid']=$valuedata['simgmid'];

            $arraydata['updateby']=$arrayuser['userid'];
            $arraydata['updatedate']=date("Y-m-d H:i:s");
            $arraydata['status']=$valuedata['status'];
            $arraydata['sort']=$valuedata['sort'];
            $arraydata['link']=$valuedata['link'];
            $arraydata['tag']=$valuedata['tag'];
            
            
              if($valuedata['ubanid'])
            {
            
            $this->db->db_set($arraydata,'tb_banner_user',' ubanid='.$valuedata['ubanid']);
            
            }else
            {
            $arraydata['createby']=$arrayuser['userid'];
            $arraydata['createdate']=date("Y-m-d H:i:s");
            
            $this->db->db_set($arraydata,'tb_banner_user');
            
            
            }
            
            
            
            }           
                   
            }
            
            }
            
            
            }
          
          
          
          }
          
          function getbanneruser()
          {
            if($this->userdata['oauth'])
            {
            $arrayuser=$this->getuserbyoauth($this->userdata['oauth']);
            if($arrayuser['userid'])
            {
          $arraydata=array();
          $sql='select * from tb_banner_public where createby='.$arrayuser['userid'];
          $arrpub=$this->db->db_set_1recordrow($sql);
          if($arrpub['pubid'])
          {
          $arrpub['img']=$this->getimagebyimgmid($arrpub['imgmid']);
          $arrpub['simg']=$this->getimagebyimgmid($arrpub['simgmid']);
          
          }
          $arraydata['pub']=$arrpub;
          
          
          $sql='select * from tb_banner_user where createby='.$arrayuser['userid'].' order by tb_banner_user.sort asc';
          $arruser=$this->db->db_set_recordset($sql);
          $k=0;
          if(count($arruser))
          {
          foreach($arruser as $valueuser)
          {
          $arruser[$k]['img']=$this->getimagebyimgmid($valueuser['imgmid']);
          $arruser[$k]['simg']=$this->getimagebyimgmid($valueuser['simgmid']);
          $k++;
          
          
          }
          
          }
          
          $arraydata['user']=$arruser;
          
          $this->arraydata['data']=$arraydata;
          
          
            }
            
            }
          
          
          
          }
          
          function add2cart()
          {
            if($this->userdata['oauth']&&$this->post['productid']&&$this->post['qty'])
           {
           
           
          
           
           $sql='select * from tb_plugins_pricefull where productid='.$this->post['productid'];
           $arraydata=$this->db->db_set_1recordrow($sql);
           
           if($arraydata['priceid'])
           {
           
           
           $sql='select createby from tb_product where productid='.$this->post['productid'];
           $arraypro=$this->db->db_set_1recordrow($sql);
           
           
           
            $sql='select shisid from tb_product_shop_history where userid='.$arraypro['createby'].' and productid='.$this->post['productid'].' and status=0 and tb_product_shop_history.delete=0 and paypoint=1 and createby='.$this->userdata['userid'];
           $arraydata2=$this->db->db_set_1recordrow($sql);
           if($arraydata2['shisid'])
           {
           
           $this->arraydata['error'][]=45;
           exit;
           
           }
           
           
           $sql='select * from tb_product_setting where createby='.$arraypro['createby'];
           $arraypro2=$this->db->db_set_1recordrow($sql);
           
           
           if($arraypro2['invent']=='0'&&$arraypro2['psetid'])
           {
           $this->add2cartproduct($arraypro['createby'],$this->post['productid'],$this->post['qty']);
           }else
           {
           if($arraydata['unlimit']=='0')
           {
           
           
           if(intval($arraydata['amount'])<intval($this->post['qty']))
           {
           
           $this->arraydata['error'][]=41;
           
           }else
           {
           
           $this->arraydata['data']=$this->add2cartproduct($arraypro['createby'],$this->post['productid'],$this->post['qty']);
           
           }
           
           
           
           }else
           {
           
           
            $this->arraydata['data']=$this->add2cartproduct($arraypro['createby'],$this->post['productid'],$this->post['qty']);
           
           }
           }
           
           
           
           
           }else
           {
           $this->arraydata['error'][]=27;
           
           
           }
           
           
           
           

           
           }
           else
           {
           $this->arraydata['error'][]=5;
           
           }
          
          }
          
          function getcount2cart()
          {
            if($this->userdata['userid'])
            {
            $sql='select count(*) as countproduct from tb_product_shop_history where tb_product_shop_history.delete=0 and status=0 and createby='.$this->userdata['userid'];;
            
            $arraycart2=$this->db->db_set_1recordrow($sql);
            
            
            $this->arraydata['data']=intval($arraycart2['countproduct']);
            }
          
          
          }
          
          function savecartmanage()
          {
            if($this->userdata['oauth'])
            {
            $arrayuser=$this->getuserbyoauth($this->userdata['oauth']);
            if($arrayuser['userid']&&intval($arrayuser['roleid'])>=2)
            {
            
            $arraydata['shopname']=$this->post['shopname'];
            $arraydata['orderprefix']=$this->post['orderprefix'];
            $arraydata['curid']=$this->post['curid'];
            $arraydata['invent']=$this->post['invent'];
            
            //$sql='delete from tb_product_transport where createby='.$arrayuser['userid'];
//            $this->db->db_delete($sql);
            $arraytrans=array();
            $arraytrans['delete']=1;
            $this->db->db_set($arraytrans,'tb_product_transport','createby='.$arrayuser['userid']);
            if(count($this->post['transportdata']))
            {
            foreach($this->post['transportdata'] as $valuetransport)
            {
            $arraytrans=array();

            $arraytrans['tspname']=$valuetransport['tspname'];
            $arraytrans['tspcost']=$valuetransport['tspcost'];
            $arraytrans['createby']=$arrayuser['userid'];
            $this->db->db_set($arraytrans,'tb_product_transport');
            
            
            }
            
            
            }
            
            $arraydata['transfer']=$this->post['transfer'];            
            $arraydata['paypal']=$this->post['paypal'];            
            $arraydata['paypalemail']=$this->post['paypalemail'];            
            $arraydata['paypoint']=$this->post['paypoint'];            
            $arraydata['point']=$this->post['point'];            
            $arraydata['paycredit']=$this->post['paycredit'];            
            $arraydata['etc']=$this->post['etc'];  
            
            $sql='select psetid from tb_product_setting where createby='.$arrayuser['userid'];
            $datacheck=$this->db->db_set_1recordrow($sql);
            if($datacheck['psetid'])
            {
            $arraydata['updatedate']=date("Y-m-d H:i:s"); 
            $this->db->db_set($arraydata,'tb_product_setting',' psetid='.$datacheck['psetid']);
            }else
            {
            $arraydata['createby']=$arrayuser['userid']; 
            $arraydata['createdate']=date("Y-m-d H:i:s"); 
            $this->db->db_set($arraydata,'tb_product_setting');
            
            }
                      
              //$sql='delete from tb_product_transfer where createby='.$arrayuser['userid'];
//            $this->db->db_delete($sql);
            $arraytrans=array();
            $arraytrans['delete']=1;
            $this->db->db_set($arraytrans,'tb_product_transfer','createby='.$arrayuser['userid']);
            if(count($this->post['transferdata']))
            {
            foreach($this->post['transferdata'] as $valuetransfer)
            {
            $arraytrans=array();

            $arraytrans['bankid']=$valuetransfer['bankid'];
            $arraytrans['accnumber']=$valuetransfer['accnumber'];
            $arraytrans['accname']=$valuetransfer['accname'];
            $arraytrans['branch']=$valuetransfer['branch'];
            $arraytrans['actypeid']=$valuetransfer['actypeid'];
            $arraytrans['createby']=$arrayuser['userid'];
            $this->db->db_set($arraytrans,'tb_product_transfer');
            
            
            }
            
            
            }
            
               $arraytrans=array();
            $arraytrans['delete']=1;
            $this->db->db_set($arraytrans,'tb_product_payment','createby='.$arrayuser['userid']);
            if(count($this->post['paymentdata']))
            {
            foreach($this->post['paymentdata'] as $valuetransfer)
            {
            $arraytrans=array();

            $arraytrans['payname']=$valuetransfer['payname'];
            $arraytrans['paydescription']=$valuetransfer['paydescription'];
            $arraytrans['createby']=$arrayuser['userid'];
            $this->db->db_set($arraytrans,'tb_product_payment');
            
            
            }
            
            
            }
            
            
            
            }
            
            }
          
          
          }
          
          function getcartmanage()
          {
            if($this->userdata['oauth'])
            {
            $arrayuser=$this->getuserbyoauth($this->userdata['oauth']);
            if($arrayuser['userid']&&intval($arrayuser['roleid'])>=2)
            {
            $this->arraydata['data']=parent::getcartmanage($arrayuser['userid']);
            
            }
            
            } 
          
          }
          
          function testadd2cart()
          {

          require_once(pluginpath.'/t2p/t2p_include.php'); // uri
          /*
    Product Information Part
    T-Shirt                    100 THB.
    SWeet T-Shirt                500 THB.
    */
    
    
   //$AppCode="s_chanyut@hotmail.com";
    //$AppPassword="c29388cd6c39d0b705ccb9c9c70472b1"; 
    
   // $AppCode="310001";
//   $AppPassword="TEST1"; 
   
       $AppCode="s_chanyut@hotmail.co";
   $AppPassword="c29388cd6c39d0b705ccb9c9c70472b1"; 
   
    
//    $ExampleInvoice = "7273678899111INV"; //Unique Invoice 
                                    //(change if page refresh)
//    $totalPrice = 600;
//    $FrontURL = "http://v19.dmconnex.com/cart";
//    $comment = "my comment for this payment";
//    
//    
//    $FrontURL=baseinfo.'/ajax/testadd2cartres';
//    
//    echo t2p_checkout_test($AppCode,  
//                              $AppPassword,   
//                              $ExampleInvoice, 
//                              $totalPrice,  
//                              $comment, 
//                              $FrontURL ,true);


$rnd = rand(100001,999999);
//echo $rnd.'<br>';
//exit;
echo  t2p_checkout_test($AppCode,$AppPassword,$rnd,1,'5Baht&test',baseinfo.'/cart',true);
          
          
          }
          
          function testbackurl()
          {
          
             require_once(pluginpath.'/t2p/t2p_include.php'); // uri
          $AppCode="s_chanyut@hotmail.co";
    $AppPassword="c29388cd6c39d0b705ccb9c9c70472b1"; 
//Enter merchant password and error code received 
            $result = t2p_result($AppCode,$AppPassword,$errCode);

            $arraydata['test']=json_encode($result);
            $this->db->db_set($arraydata,'tb_log');
         If($result){
                // Return value of $result will be in Array of transmitted values 
                //$result[“AppCode”]
                //$result[“InvoiceNo”]
                //$result[“Amount”]
                //$result[“TXID”]
                //$result[“ReturnCode”]
                //$result[“Sum”]
                //Merchant Process Success   and keep log
                echo 'OK'; //If Success MUST echo  only “OK” no other warnning msg.
            }else{ 
                echo 'eror';
            }

          
          }
          
          function testadd2cartres()
          {
          
          require_once(pluginpath.'/t2p/t2p_include.php'); // uri
          $AppCode="s_chanyut@hotmail.co";
    $AppPassword="c29388cd6c39d0b705ccb9c9c70472b1"; 
//Enter merchant password and error code received 
            $result = t2p_result($AppCode,$AppPassword,$errCode);

         If($result){
                // Return value of $result will be in Array of transmitted values 
                //$result[“AppCode”]
                //$result[“InvoiceNo”]
                //$result[“Amount”]
                //$result[“TXID”]
                //$result[“ReturnCode”]
                //$result[“Sum”]
                //Merchant Process Success   and keep log
                echo 'OK'; //If Success MUST echo  only “OK” no other warnning msg.
            }else{ 
                echo 'eror';
            }

          
          }
           
           function savequestiondataq()
           {
           if($this->post)
           {
             $arraydata=$this->post;
             unset($arraydata['ans']);
             $arraydata['createdate']=date("Y-m-d H:i:s");
             $this->db->db_set($arraydata,'tb_question_ans');
             $ansid=$this->db->db_get_last_number();
             if(count($this->post['ans']))
             {
             foreach($this->post['ans'] as $key=> $valueans)
             {
             $arraydatanew=array();
             $arraydatanew['ansid']=$ansid;
             $arraydatanew['qid']=$key;
             $arraydatanew['ans']=$valueans;
             $this->db->db_set($arraydatanew,'tb_question_sans');
             
             }
             
             }
             
             $sql='select ans,qid from tb_question_sans where ansid='.$ansid.' order by tb_question_sans.qid asc';
             $arraycheck=$this->db->db_set_recordset($sql);
             
             
             $sql='SELECT
tb_question_sans.ansid,
tb_question_sans.qid,
tb_question_sans.ans
FROM
tb_question_sans
INNER JOIN tb_question_ans ON tb_question_ans.ansid = tb_question_sans.ansid
where tb_question_ans.status=1';
            $arrayquestion=$this->db->db_set_recordset($sql);
            $arraynewcheck=array();
            if(count($arrayquestion))
            {
            foreach($arrayquestion as $valueq)
            {
            $arraynewcheck[$valueq['ansid']][$valueq['qid']]=$valueq['ans'];
            
            }
            
            }
             $arrayscore=array();
             if(count($arraynewcheck))
             {
             foreach($arraynewcheck as $keycheck=> $valuecheck)
            {
                  if(count($arraycheck))
                  {
                   foreach($arraycheck as  $valuecheck2)
            {
                 if($valuecheck[$valuecheck2['qid']]==$valuecheck2['ans'])
                 {
                    if($arrayscore[$keycheck])
                    {
                    $arrayscore[$keycheck]=$arrayscore[$keycheck]+1;
                    }else
                    {
                    $arrayscore[$keycheck]=1;
                    
                    }
                 
                 }
            
            }
                  
                  }
            
              // if(count($valuecheck))
//               {
//               foreach($valuecheck as $keycheck2 => $valuecheck2)
//               {
//               
//               $arrayscore
//               
//               }
//               
//               }
            
            }
             
             }
             
             
             
             

uasort($arrayscore, 'cmp');
 
            foreach($arrayscore as $keyscore => $valuescore)
            {
            $keyscore1=$keyscore;
            
            break;
            }
            $sql='select *  from tb_question_ans where ansid='.$keyscore1.'';
           $arraycheck3=$this->db->db_set_1recordrow($sql);
           $this->arraydata['data']=$arraycheck3;
           }
           
           }
           
           function paywithpaypal()
           {
           require pluginpath.'/paypal/paypal.class.php';
           
           $paypalmode = (PayPalMode=='sandbox') ? '.sandbox' : '';
           $PayPalReturnURL=serviceinfo.'checkconfirmpaypal?nojson=1';
           $PayPalCancelURL=baseinfo.'/cart';
           $padata =     '&METHOD=SetExpressCheckout'.
                '&RETURNURL='.urlencode($PayPalReturnURL ).
                '&CANCELURL='.urlencode($PayPalCancelURL).
                '&PAYMENTREQUEST_0_PAYMENTACTION='.urlencode("SALE");
                
                
            $arrayuser=$this->getuserbyoauth($this->userdata['oauth']);
          if($this->get['orderid']&&$arrayuser['userid'])
          {
          $sql='SELECT
tb_product_order.orderid,
tb_product_order.point,
tb_product_order.`status`,
tb_product_order.sumall,
tb_product_order.cash,
tb_product_order.`change`,
tb_product_order.userid,
tb_product_order.payid,
tb_product_order.tspoid,
tb_product_order.tfid,
tb_product_order.cart,
tb_product_order.cartstatus,
tb_product_order.updateby,
tb_product_order.createby,
tb_product_order.updatedate,
IF (tb_product_setting.shopname is NULL,tb_user.displayname,tb_product_setting.shopname) as displayname,
IF (tb_product_setting.orderprefix is NULL,\'\',tb_product_setting.orderprefix) as orderprefix,
DATE_FORMAT(tb_product_order.createdate,\'%T %d/%m/%Y\') as newdate,
tb_user.username,
tb_user.simgmid,
tb_product_order.createdate
FROM
tb_product_order
INNER JOIN tb_user ON tb_product_order.createby=tb_user.userid
LEFT JOIN tb_product_setting ON tb_product_order.createby=tb_product_setting.createby
where tb_product_order.orderid='.$this->get['orderid'].' and tb_product_order.userid='.$arrayuser['userid'];
            $arrrayorder=$this->db->db_set_1recordrow($sql);
            
            if($arrrayorder['orderid'])
            {
            
            $sql='select * from tb_product_transport where tspoid='.$arrrayorder['tspoid'];
            $arrrayorder['transport']=$this->db->db_set_1recordrow($sql);
            
            
            
            $sql='SELECT
tb_product_suborder.suborderid,
tb_product_suborder.productid,
tb_product_suborder.credit,
tb_product_suborder.point,
tb_product_suborder.count,
tb_product_suborder.`delete`,
tb_product_suborder.orderid,
tb_product_suborder.title,
tb_product_suborder.note,
tb_product_suborder.discount,
tb_product_suborder.price,
tb_product.title,
tb_product.simgmid
FROM
tb_product_suborder
INNER JOIN tb_product ON tb_product_suborder.productid = tb_product.productid
where tb_product_suborder.orderid='.$arrrayorder['orderid'];
            
            $arrrayorder['suborder']=$this->db->db_set_recordset($sql);
            $arrrayorder['simg']=$this->getimagebyimgmid($arrrayorder['simgmid']);
            $sumall=0;
            $rowsetdata=0;
            if(count($arrrayorder['suborder']))
            {
            foreach($arrrayorder['suborder'] as $valuesuborder)
            {
            
       //     $arrrayorder['suborder'][$k]['simg']=$this->getimagebyimgmid($valuesuborder['simgmid']);
         //   $arrrayorder['suborder'][$k]['sum']=intval($valuesuborder['price'])*intval($valuesuborder['count']);
            
            
                if(intval($valuesuborder['price'])>0)
                {
               $padata.= '&L_PAYMENTREQUEST_0_NAME'.$rowsetdata.'='.urlencode($valuesuborder['title']).
                '&L_PAYMENTREQUEST_0_NUMBER'.$rowsetdata.'='.urlencode($valuesuborder['productid']).
                '&L_PAYMENTREQUEST_0_DESC'.$rowsetdata.'='.urlencode($valuesuborder['note']).
                '&L_PAYMENTREQUEST_0_AMT'.$rowsetdata.'='.urlencode($valuesuborder['price']).
                '&L_PAYMENTREQUEST_0_QTY'.$rowsetdata.'='. urlencode($valuesuborder['count']);
                
                $rowsetdata++;
            
                $sumall+=intval($valuesuborder['price'])*intval($valuesuborder['count']);
                }

            
            }
            
            }
            
            if($arrrayorder['transport']['tspoid'])
            {
            $padata.='&NOSHIPPING=0';
            $padata.='&PAYMENTREQUEST_0_SHIPPINGAMT='.urlencode($arrrayorder['transport']['tspcost']);
            }else
            {
            $padata.='&NOSHIPPING=1';
            
            }
          
            $padata.='&PAYMENTREQUEST_0_ITEMAMT='.urlencode($sumall);
            $padata.='&PAYMENTREQUEST_0_AMT='.urlencode($arrrayorder['sumall']);
            $padata.='&PAYMENTREQUEST_0_CURRENCYCODE='.urlencode(PayPalCurrencyCode).
                '&LOCALECODE=GB'. //PayPal pages to match the language on your website.
                '&LOGOIMG='.$arrrayorder['simg']['newpath']. //site logo
                '&CARTBORDERCOLOR=FFFFFF'. //border color of cart
                '&ALLOWNOTE=1';
            
            
          //  echo $padata;
            
            $paypal= new MyPayPal();
        $httpParsedResponseAr = $paypal->PPHttpPost('SetExpressCheckout', $padata, PayPalApiUsername, PayPalApiPassword, PayPalApiSignature, PayPalMode);
        
        //Respond according to message we receive from Paypal
        if("SUCCESS" == strtoupper($httpParsedResponseAr["ACK"]) || "SUCCESSWITHWARNING" == strtoupper($httpParsedResponseAr["ACK"]))
        {

                //$_SESSION['orderidset']=$arrrayorder['orderid'];
                $arrayset=array();
                $arrayset['token']=$httpParsedResponseAr["TOKEN"];
                $arrayset['orderid']=$arrrayorder['orderid'];
                $arrayset['createby']=$arrayuser['userid'];
                $arrayset['createdate']=date("Y-m-d H:i:s");
                $arrayset['updatedate']=date("Y-m-d H:i:s");
                $this->db->db_set($arrayset,'tb_paypal_code');

                //Redirect user to PayPal store with Token received.
                 $paypalurl ='https://www'.$paypalmode.'.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token='.$httpParsedResponseAr["TOKEN"].'';
                header('Location: '.$paypalurl);
             
        }
        else{
         echo $padata;
            //Show error message
            echo '<div style="color:red"><b>Error : </b>'.urldecode($httpParsedResponseAr["L_LONGMESSAGE0"]).'</div>';
            echo '<pre>';
            print_r($httpParsedResponseAr);
            echo '</pre>';
        }    
        
            

            
            
            
            
            }
            else
            {
            $htis->arraydata['error'][]=26;
            }
          
          
          }
          
           
           
           
           
           }
           
           function checkconfirmpaypal()
           {
           
if(isset($_GET["token"]) && isset($_GET["PayerID"]))
{
           require pluginpath.'/paypal/paypal.class.php';
    //we will be using these two variables to execute the "DoExpressCheckoutPayment"
    //Note: we haven't received any payment yet.
    
    $token = $_GET["token"];
    $payer_id = $_GET["PayerID"];
    
    
          $orderid=$_SESSION['orderidset'];
       
           
           $paypalmode = (PayPalMode=='sandbox') ? '.sandbox' : '';
           
           $padata =     '&TOKEN='.urlencode($token).
                '&PAYERID='.urlencode($payer_id).
                '&PAYMENTREQUEST_0_PAYMENTACTION='.urlencode("SALE");
           $arrayuser=$this->getuserbyoauth($this->userdata['oauth']);    
           $sql='select * from tb_paypal_code where tb_paypal_code.token="'.str_replace('-','%2d',urlencode($token)).'" and tb_paypal_code.createby='.$arrayuser['userid'];
           
           $arraycheck2=$this->db->db_set_1recordrow($sql);
           
           $orderid=$arraycheck2['orderid'];
                
            
          if($orderid&&$arrayuser['userid'])
          {
          $sql='SELECT
tb_product_order.orderid,
tb_product_order.point,
tb_product_order.`status`,
tb_product_order.sumall,
tb_product_order.cash,
tb_product_order.`change`,
tb_product_order.userid,
tb_product_order.payid,
tb_product_order.tspoid,
tb_product_order.tfid,
tb_product_order.cart,
tb_product_order.cartstatus,
tb_product_order.updateby,
tb_product_order.createby,
tb_product_order.updatedate,
IF (tb_product_setting.shopname is NULL,tb_user.displayname,tb_product_setting.shopname) as displayname,
IF (tb_product_setting.orderprefix is NULL,\'\',tb_product_setting.orderprefix) as orderprefix,
DATE_FORMAT(tb_product_order.createdate,\'%T %d/%m/%Y\') as newdate,
tb_user.username,
tb_user.simgmid,
tb_product_order.createdate
FROM
tb_product_order
INNER JOIN tb_user ON tb_product_order.createby=tb_user.userid
LEFT JOIN tb_product_setting ON tb_product_order.createby=tb_product_setting.createby
where tb_product_order.orderid='.$orderid.' and tb_product_order.userid='.$arrayuser['userid'];
            $arrrayorder=$this->db->db_set_1recordrow($sql);
            
            if($arrrayorder['orderid'])
            {
            
            $sql='select * from tb_product_transport where tspoid='.$arrrayorder['tspoid'];
            $arrrayorder['transport']=$this->db->db_set_1recordrow($sql);
            
            
            
            $sql='SELECT
tb_product_suborder.suborderid,
tb_product_suborder.productid,
tb_product_suborder.credit,
tb_product_suborder.point,
tb_product_suborder.count,
tb_product_suborder.`delete`,
tb_product_suborder.orderid,
tb_product_suborder.title,
tb_product_suborder.note,
tb_product_suborder.discount,
tb_product_suborder.price,
tb_product.title,
tb_product.simgmid
FROM
tb_product_suborder
INNER JOIN tb_product ON tb_product_suborder.productid = tb_product.productid
where tb_product_suborder.orderid='.$arrrayorder['orderid'];
            
            $arrrayorder['suborder']=$this->db->db_set_recordset($sql);
            $arrrayorder['simg']=$this->getimagebyimgmid($arrrayorder['simgmid']);
            $sumall=0;
            $rowsetdata=0;
            if(count($arrrayorder['suborder']))
            {
            foreach($arrrayorder['suborder'] as $valuesuborder)
            {
            
       //     $arrrayorder['suborder'][$k]['simg']=$this->getimagebyimgmid($valuesuborder['simgmid']);
         //   $arrrayorder['suborder'][$k]['sum']=intval($valuesuborder['price'])*intval($valuesuborder['count']);
            
            
                if(intval($valuesuborder['price'])>0)
                {
               $padata.= '&L_PAYMENTREQUEST_0_NAME'.$rowsetdata.'='.urlencode($valuesuborder['title']).
                '&L_PAYMENTREQUEST_0_NUMBER'.$rowsetdata.'='.urlencode($valuesuborder['productid']).
                '&L_PAYMENTREQUEST_0_DESC'.$rowsetdata.'='.urlencode($valuesuborder['note']).
                '&L_PAYMENTREQUEST_0_AMT'.$rowsetdata.'='.urlencode($valuesuborder['price']).
                '&L_PAYMENTREQUEST_0_QTY'.$rowsetdata.'='. urlencode($valuesuborder['count']);
            
                $sumall+=intval($valuesuborder['price'])*intval($valuesuborder['count']);
                
                $rowsetdata++;
                }

            
            }
            
            }
            
            if($arrrayorder['transport']['tspoid'])
            {
            $padata.='&NOSHIPPING=0';
            $padata.='&PAYMENTREQUEST_0_SHIPPINGAMT='.urlencode($arrrayorder['transport']['tspcost']);
            }else
            {
            $padata.='&NOSHIPPING=1';
            
            }
          
            $padata.='&PAYMENTREQUEST_0_ITEMAMT='.urlencode($sumall);
            $padata.='&PAYMENTREQUEST_0_AMT='.urlencode($arrrayorder['sumall']);
            $padata.='&PAYMENTREQUEST_0_CURRENCYCODE='.urlencode(PayPalCurrencyCode).
                '&LOCALECODE=GB'. //PayPal pages to match the language on your website.
                '&LOGOIMG='.$arrrayorder['simg']['newpath']. //site logo
                '&CARTBORDERCOLOR=FFFFFF'. //border color of cart
                '&ALLOWNOTE=1';
            
            
          //  echo $padata;
            
          $paypal= new MyPayPal();
    $httpParsedResponseAr = $paypal->PPHttpPost('DoExpressCheckoutPayment', $padata, PayPalApiUsername, PayPalApiPassword, PayPalApiSignature, PayPalMode);
    

    //Check if everything went ok..
    if("SUCCESS" == strtoupper($httpParsedResponseAr["ACK"]) || "SUCCESSWITHWARNING" == strtoupper($httpParsedResponseAr["ACK"])) 
    {

        //    echo '<h2>Success</h2>';
//            echo 'Your Transaction ID : '.urldecode($httpParsedResponseAr["PAYMENTINFO_0_TRANSACTIONID"]);
//            
                /*
                //Sometimes Payment are kept pending even when transaction is complete. 
                //hence we need to notify user about it and ask him manually approve the transiction
                */
                
                if('Completed' == $httpParsedResponseAr["PAYMENTINFO_0_PAYMENTSTATUS"])
                {
                //    echo '<div style="color:green">Payment Received! Your product will be sent to you very soon!</div>';
                }
                elseif('Pending' == $httpParsedResponseAr["PAYMENTINFO_0_PAYMENTSTATUS"])
                {
                //    echo '<div style="color:red">Transaction Complete, but payment is still pending! '.
//                    'You need to manually authorize this payment in your <a target="_new" href="http://www.paypal.com">Paypal Account</a></div>';
                }

                // we can retrive transection details using either GetTransactionDetails or GetExpressCheckoutDetails
                // GetTransactionDetails requires a Transaction ID, and GetExpressCheckoutDetails requires Token returned by SetExpressCheckOut
                $padata =     '&TOKEN='.urlencode($token);
                $paypal= new MyPayPal();
                $httpParsedResponseAr = $paypal->PPHttpPost('GetExpressCheckoutDetails', $padata, PayPalApiUsername, PayPalApiPassword, PayPalApiSignature, PayPalMode);

                if("SUCCESS" == strtoupper($httpParsedResponseAr["ACK"]) || "SUCCESSWITHWARNING" == strtoupper($httpParsedResponseAr["ACK"])) 
                {
                    
                   // echo '<br /><b>Stuff to store in database :</b><br /><pre>';
                    /*
                    #### SAVE BUYER INFORMATION IN DATABASE ###
                    //see (http://www.sanwebe.com/2013/03/basic-php-mysqli-usage) for mysqli usage
                    
                    $buyerName = $httpParsedResponseAr["FIRSTNAME"].' '.$httpParsedResponseAr["LASTNAME"];
                    $buyerEmail = $httpParsedResponseAr["EMAIL"];
                    
                    //Open a new connection to the MySQL server
                    $mysqli = new mysqli('host','username','password','database_name');
                    
                    //Output any connection error
                    if ($mysqli->connect_error) {
                        die('Error : ('. $mysqli->connect_errno .') '. $mysqli->connect_error);
                    }        
                    
                    $insert_row = $mysqli->query("INSERT INTO BuyerTable 
                    (BuyerName,BuyerEmail,TransactionID,ItemName,ItemNumber, ItemAmount,ItemQTY)
                    VALUES ('$buyerName','$buyerEmail','$transactionID','$ItemName',$ItemNumber, $ItemTotalPrice,$ItemQTY)");
                    
                    if($insert_row){
                        print 'Success! ID of last inserted record is : ' .$mysqli->insert_id .'<br />'; 
                    }else{
                        die('Error : ('. $mysqli->errno .') '. $mysqli->error);
                    }
                    
                    */
                    $arraycheck3=array();
                    $arraycheck3['status']=2;
                    $arraycheck3['response']=json_encode($httpParsedResponseAr);
                    $arraycheck3['updatedate']=date("Y-m-d H:i:s");
                    $this->db->db_set($arraycheck3,'tb_paypal_code',' tokenid='.$arraycheck2['tokenid']);
                    
                    $arraydata=array();
                    $arraydata['status']=2;
                    $this->db->db_set($arraydata,'tb_product_order',' orderid='.$orderid);
            
            
             $sql='select userid,createby from tb_product_order where orderid='.$orderid;
            
            $arrayproduct=$this->db->db_set_1recordrow($sql);
            
             $sql='select 

IF (tb_product_setting.orderprefix is NULL,\'\',tb_product_setting.orderprefix) as orderprefix

from tb_user 

 LEFT JOIN tb_product_setting ON tb_user.userid = tb_product_setting.createby

 where tb_user.userid='.$arrayproduct['createby'];
 
            $arraysetting=$this->db->db_set_1recordrow($sql);
            
            
            
            if($arraydata['status']=='2')
            {
            
            $this->sendemailpaybyorderid($orderid);
            
            
            
           $msgto='ได้รับยอดเงินเรียบร้อยแล้ว‏ (Order Id:'.$arraysetting['orderprefix'].$orderid.')';       
           $userid=$arrayproduct['userid'];
           $arraydataset['userid']=$userid;
           $arraydataset['createby']=$arrayproduct['createby'];
           $arraydataset['conid']=0;
           $arraydataset['smsgid']=$this->savesupermsg($msgto,0,$orderid,1);
           $notiid[$userid]=$this->savenotificationlist($arraydataset);
    
            $arraydatanow[]=$userid;
            $this->sendtonotification($arraydatanow,$msgto,$notiid);
            
            
            
            
             $msgto='ลูกค้าสั่งซื้อสินค้าคุณผ่าน PayPal เรียบร้อยแล้ว  (Order Id:'.$arraysetting['orderprefix'].$orderid.')';       
           
           $arraydataset['userid']=$arrayproduct['createby'];
           $arraydataset['createby']=$userid;
           $arraydataset['conid']=0;
           $arraydataset['smsgid']=$this->savesupermsg($msgto,0,$orderid,2);
           $notiid=array();
           $notiid[$arrayproduct['createby']]=$this->savenotificationlist($arraydataset);
         
            $arraydatanow=array();
            $arraydatanow[]=$arrayproduct['createby'];
            $this->sendtonotification($arraydatanow,$msgto,$notiid);
            
            
            
            }
                    
                    
                } 
                else  
                {
                  //  echo '<div style="color:red"><b>GetTransactionDetails failed:</b>'.urldecode($httpParsedResponseAr["L_LONGMESSAGE0"]).'</div>';
//                    echo '<pre>';
//                    print_r($httpParsedResponseAr);
//                    echo '</pre>';

                }
    
    }
    
    else{
          //  echo '<div style="color:red"><b>Error : </b>'.urldecode($httpParsedResponseAr["L_LONGMESSAGE0"]).'</div>';
//            echo '<pre>';
//            print_r($httpParsedResponseAr);
//            echo '</pre>';
    }

    }
        
            

            
            
            
            
            }
            else
            {
            $htis->arraydata['error'][]=26;
            }
            
          $linkto=baseinfo.'/cart?orderid='.$orderid;
          header('Location: '.$linkto);
          exit;
}
          
    
 
    
    //We need to execute the "DoExpressCheckoutPayment" at this point to Receive payment from user.
  

           
           
           }
              
            function iupload2()
            {
             if($this->userdata['oauth'])
             {
             $oauth=$this->userdata['oauth'];
             $arrayuser=$this->getuserbyoauth($oauth);
             
             }else
             {
             
             $arrayuser['userid']='0';
             
             }
             
             
             
             if($_FILES["Filedata"]["tmp_name"])
             {
             
             if($this->checkallowuserspace($arrayuser['userid']))
             {
             
             $newfie=mktime().'-'.rand(0,100000);
             
             
             if(!is_dir(cacheimgpath.'/user/'.$arrayuser['userid']))
                     {
                      mkdir(cacheimgpath.'/user/'.$arrayuser['userid'],0777);
                      chmod(cacheimgpath.'/user/'.$arrayuser['userid'],0777);
                      }
                      
             $folder=cacheimgpath.'/user/'.$arrayuser['userid'];
             
              $typefile=".jpg";
              if($this->post['typefile'])
              {
              $typefile=".".$this->post['typefile'];
              }
                      
             if(move_uploaded_file($_FILES["Filedata"]["tmp_name"], $folder.'/'.$newfie.$typefile)) 
                   {
                   
                   
                   @chmod($folder.'/'.$newfie.$typefile,0777);
                   $this->rotateimage($folder.'/'.$newfie.$typefile);
                   list($width, $height, $type, $attr) = getimagesize($folder.'/'.$newfie.$typefile);
                   $this->arraydata['filelink']=str_replace(rootpath,baseinfo,$folder).'/'.$newfie.$typefile;
                   $this->arraydata['filename']=$newfie.$typefile; 
                   
                   $this->arraydata['width']=$width;
                   $this->arraydata['height']=$height;
                   $this->arraydata['imgmid']=$this->saveimage($width,$height,$folder.'/'.$newfie.$typefile,1,'','',$this->post['imgname'],1);
                   
                   
                   
          
                   
                   
                   }
             }else
             {
             $this->arraydata['error'][]=15;
             
             }
             
             }
             else
             {
             $this->arraydata['error'][]=16;
             
             }
             
             
             }
             
             function savewarrantydata()
             {
             
             if($this->post['name']&&$this->post['email']&&$this->post['phone']&&$this->post['serial']&&$this->post['day']&&$this->post['month']&&$this->post['year']&&$this->post['war1']&&$this->post['war2']&&$this->post['war3']&&$this->post['war4']&&$this->post['war5']&&$this->post['war6']&&$this->post['imgmid'])
             {
             
             
                
                $sql='select warid from tb_warranty where tb_warranty.email="'.$this->post['email'].'"';
                $warrayty=$this->db->db_set_1recordrow($sql);
                if($warrayty['warid'])
                {
                
                $this->arraydata['error'][]=8;
                return false;
                }
                
                
                $sql='select warid from tb_warranty where tb_warranty.phone="'.$this->post['phone'].'"';
                $warrayty=$this->db->db_set_1recordrow($sql);
                if($warrayty['warid'])
                {
                
                $this->arraydata['error'][]=8;
                return false;
                }
                
                 if($this->userdata['oauth'])
                 {
                 $arrayuser=$this->getuserbyoauth($this->userdata['oauth']);
                 
                 }
                 
                  $sql='select warid from tb_warranty where tb_warranty.serial="'.$this->post['serial'].'"';
                $warrayty=$this->db->db_set_1recordrow($sql);
                if($warrayty['warid'])
                {
                
                $this->arraydata['error'][]=36;
                return false;
                }
                
                
                   
                        //  $status= $this->checkserial($this->post['serial']);
                          
                          
                          $text=$this->gotocheck($this->post['serial'],1);
           
                         if($text!='NULL'&&$$arrayuser['userid'])
                         {
                          
                          $arraydata['serial']=$this->post['serial'];
                          $arraydata['model']=$text;
                          $arraydata['modelid']=1;
                          $arraydata['createby']=$arrayuser['userid'];
                          $arraydata['createdate']=date("Y-m-d H:i:s");
                          
                          $this->db->db_set($arraydata,'tb_serial');
                          
                          if(NameDmconnex=="Canonlife"){ 
                          
                          
                           $arraydata2=array();
                           $arraydata2['roleid']=2;
                           $this->db->db_set($arraydata2,'tb_user',' userid='.$userid);
                          
                          }
                          
                          
                          
                          }
                          else if($text=='NULL')
                         {
                          
                          $this->arraydata['error'][]=35;
                          return false;
                          
                          }
                          
                         $arraydata=array();
                         $arraydata['name']=$this->post['name'];
                         $arraydata['email']=$this->post['email'];
                         $arraydata['phone']=$this->post['phone'];
                         $arraydata['serial']=$this->post['serial'];
                         
                         if($arrayuser['userid'])$arraydata['userid']=$arrayuser['userid'];
                         else $arraydata['userid']=0;
                         
                         $arraydata['dateregister']=$this->post['year'].'-'.$this->post['month'].'-'.$this->post['day'];
                         $arraydata['warnum']=$this->post['war1'].$this->post['war2'].$this->post['war3'].$this->post['war4'].$this->post['war5'].$this->post['war6'];
                         $arraydata['imgmid']=$this->post['imgmid'];
                         $arraydata['simgmid']=$this->post['imgmid'];
                         $arraydata['createdate']=date("Y-m-d H:i:s");
                         
                         $this->db->db_set($arraydata,'tb_warranty');
                         
                         
                          
                          
               
                
                
                
                
                
             
             
             
             
             
             
             }else
             {
             
             $this->arraydata['error'][]=4;
             
             }
             
             
             }
             
             function saveuserdatacanon()
             {
             $userid=0;
             
             
             if(!$this->post['serialuser'])
             {
             
                            $this->arraydata['error'][]=4;
                             exit;
             }else
             {
             
                            $serialnumber=$this->post['serialuser'];
                            $sql='select serialid,createby  from tb_serial where serial="'.$serialnumber.'"';
                            $arrayserial=$this->db->db_set_1recordrow($sql);
                            if($arrayserial['serialid'])
                            {
                            $this->arraydata['error'][]=36;
                             exit;
                            
                            }
             
             
             }
             
             
             if(!$this->userdata['userid'])
             {
             
             if(!$this->post['emailnameuser']||!$this->post['fistnameuser']||!$this->post['lastnameuser'])
             {
             
                            $this->arraydata['error'][]=4;
                             exit;
             }
             
             
                        
                     if($userid==0)
                       {
                       $email=$this->post['emailnameuser'];
                       $check2=$this->checkemail($email);
          
                       if($check2==1)
                       {
                       list($username,$p)=explode("@",$email);
                       
                       
                       $userArray['username']=$username.'-'.mktime();
                       $userArray['displayname']=$username;
                       $userArray['email']=$email;
                       $password=substr(md5($username.(mktime()+rand(0,100000))),0,8);
                       $md5password=md5($password.'-123456');
                       $userArray['password']=$md5password;
                       $userArray['oauth']=md5(mktime().$md5password);
                       $userArray['status']=1;
                       $userArray['firstname']=$this->post['fistnameuser'];
                       $userArray['lastname']=$this->post['lastnameuser'];
                       
                       //$userArray['passwordset']=$password;
                       
                       
                       
                       
                       $userid=$this->saveregister($userArray,1);
          // $this->savescoredata($userid,2);
                      //  $this->savegamenictaionbygxcid($userid,2);
                       
                       $userArray['userid']=$userid;
                       $this->arraydata['data']=$userArray;
                       $this->post['oauth']=$userArray['oauth'];
                    //   exit;
                        $this->login();

                       require_once(pluginpath.'/phpmailer/class.config.php'); // uri
           
                        $mail = new ConfigMail();
           //$mail->setFrom("s_chanyut@hotmail.com","Bird Kung");
                       $mail->setTo($email,$username);
                       $mail->setContent(' Username:'.$userArray['username'].'<br>Password:'.$password);
                       if(NameDmconnex=='Canonlife')
                       {
                       $mail->setSubject("ยินดีต้อนรับสู่ ".NameDmconnex);
                       
                       }else
                       {
                       
                      $mail->setSubject("Welcome to ".NameDmconnex); 
                       
                       }
                       
                       $mail->sendTo();
                       
                       
                       }else
                       {
                       
                       
                       
                       $this->arraydata['error'][]=$check2;
                       exit;
                       }
                       }
                       
                       
             
             
             }
             else
             {
             $userdata=$this->getuserbyoauth($this->userdata['oauth']);
             $userid=$userdata['userid'];
             
             }
             
             $this->arraydata['data']['userid']=$userid;
             
             if($this->post['serialuser']&&$userid)
             {
             
                            $serialnumber=$this->post['serialuser'];
                            $sql='select serialid,createby  from tb_serial where serial="'.$serialnumber.'"';
                            $arrayserial=$this->db->db_set_1recordrow($sql);
                            if($arrayserial['serialid'])
                            {
                            $this->arraydata['error'][]=36;
                             exit;
                            
                            }else
                            {
                            
                            $arraydata2['serial']=$serialnumber;
                            $arraydata2['createby']=$userid;
                            $arraydata2['createdate']=date("Y-m-d H:i:s");
                            $this->db->db_set($arraydata2,'tb_serial');
                            
                            
                            
                            }
                            
                            
                            
             
             
             }
             else
             {

             
             }
             
             
             
             }
             
             function saveproductdatacanon()
             {
             $arrayuser=$this->getuserbyoauth($this->userdata['oauth']);
             $userid=$arrayuser['userid'];
             if($userid&&$this->post['title'])
             {
             $featurearray=$this->getfeaturebyname('canonprofess');
             
             $sql='select count(*) as countproduct from tb_product where tb_product.fid='.$featurearray['fid'].' and tb_product.createby='.$arrayuser['userid'].' and tb_product.delete=0';
             $checkcountproduct=$this->db->db_set_1recordrow($sql);
             if(intval($checkcountproduct['countproduct'])<4)
             {
             
             $arraydata['title']=  $this->post['title'];
            getFilesFromDirMuti(includepath,$arraynow);
             if(array_search_r_like($this->post['title'], $arraynow)||array_search_r_like($this->post['title'], $this->info['configall']['feature']))
            {
            $this->post['title']=$this->post['title'].'1';
            }
            $arraydata['link']=str_replace(array("/"," ","?","&",";","#","'",'"','%'),"-",strip_tags(trim($this->post['title']))) ;
            $arraydata['fid']=$featurearray['fid'];
            $arraydata['updatedate']=date("Y-m-d H:i:s");
            $arraydata['createdate']=date("Y-m-d H:i:s");
            
            $arraydata['imgmid']=$this->post['imgmid'];
            $arraydata['simgmid']=$this->post['simgmid'];
            
            
            $arraydata['updateby']=$arrayuser['userid'];
            $arraydata['createby']=$arrayuser['userid'];
            
            
            $arraydata['status']=2;
            
            
            
            

            
            $this->db->db_set($arraydata,"tb_product");
            $productid=$this->db->db_get_last_number();
            
            
            if(!is_dir(imgpath.'/'.$productid))
            {
            mkdir(imgpath.'/'.$productid,0777);
            chmod(imgpath.'/'.$productid,0777);
            }
            if(!is_dir(filepath.'/'.$productid))
            {
            mkdir(filepath.'/'.$productid,0777);
            chmod(filepath.'/'.$productid,0777);
            }
            
            
                $this->post['tagsystem']=array();
                $this->post['taguser']='#CPW2014 #'.$this->post['contest'];
                $this->savetag($this->post['tagsystem'],$this->post['taguser'],$productid,$arraydata['fid']);
                

                
                
                if(count($this->post['plugin']))
            {
            $this->saveplugins($this->post['plugin'],$productid);
            }
            
            
            
            $this->arraydata['data']['link']=$arraydata['link'];
            $this->arraydata['data']['productid']=$productid;
            
            
            
                
                
             }else
             {
             
                          $this->arraydata['error'][]=5;
             exit;
             
             
             }
            
             }else
             {
             
             $this->arraydata['error'][]=5;
             exit;
             
             }
             
             
             
             }
             

      }
?>
